diff --git a/.gitignore b/.gitignore
index 415f4e8..f41df74 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
/.idea
/zk-single-kafka-single
+/data0
+/data1
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 0b0b3b5..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,21 +0,0 @@
-FROM maven:3.6.3-openjdk-8-slim AS build
-COPY demo-command/src /usr/src/demo-cqrs/demo-command/src
-COPY demo-command/pom.xml /usr/src/demo-cqrs/demo-command
-COPY demo-query/src /usr/src/demo-cqrs/demo-query/src
-COPY demo-query/pom.xml /usr/src/demo-cqrs/demo-query
-COPY pom.xml /usr/src/demo-cqrs
-RUN mvn -f /usr/src/demo-cqrs/pom.xml clean package
-
-FROM openjdk:8-alpine AS demo-command
-RUN addgroup -S spring && adduser -S spring -G spring
-USER spring:spring
-COPY --from=build /usr/src/demo-cqrs/demo-command/target/demo-command-0.0.1-SNAPSHOT.jar /usr/app/demo-command-0.0.1-SNAPSHOT.jar
-EXPOSE 8081
-ENTRYPOINT ["java","-jar","/usr/app/demo-command-0.0.1-SNAPSHOT.jar"]
-
-FROM openjdk:8-alpine AS demo-query
-RUN addgroup -S spring && adduser -S spring -G spring
-USER spring:spring
-COPY --from=build /usr/src/demo-cqrs/demo-query/target/demo-query-0.0.1-SNAPSHOT.jar /usr/app/demo-query-0.0.1-SNAPSHOT.jar
-EXPOSE 8082
-ENTRYPOINT ["java","-jar","/usr/app/demo-query-0.0.1-SNAPSHOT.jar"]
\ No newline at end of file
diff --git a/data0/WiredTiger b/data0/WiredTiger
new file mode 100644
index 0000000..b7f2a1b
--- /dev/null
+++ b/data0/WiredTiger
@@ -0,0 +1,2 @@
+WiredTiger
+WiredTiger 10.0.0: (March 18, 2020)
diff --git a/data0/WiredTiger.lock b/data0/WiredTiger.lock
new file mode 100644
index 0000000..3d84206
--- /dev/null
+++ b/data0/WiredTiger.lock
@@ -0,0 +1 @@
+WiredTiger lock file
diff --git a/data0/WiredTiger.turtle b/data0/WiredTiger.turtle
new file mode 100644
index 0000000..7fbb69e
--- /dev/null
+++ b/data0/WiredTiger.turtle
@@ -0,0 +1,6 @@
+WiredTiger version string
+WiredTiger 10.0.0: (March 18, 2020)
+WiredTiger version
+major=10,minor=0,patch=0
+file:WiredTiger.wt
+access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1),checkpoint=(WiredTigerCheckpoint.45=(addr="018381e4539bcb7f8481e41f4fdcd18581e4d2e42e9a808080e3010fc0e23fc0",order=45,time=1612453682,size=28672,newest_start_durable_ts=0,oldest_start_ts=0,newest_txn=23,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=120,run_write_gen=98)),checkpoint_backup_info=,checkpoint_lsn=(8,19072)
diff --git a/data0/WiredTiger.wt b/data0/WiredTiger.wt
new file mode 100644
index 0000000..f1af0a6
Binary files /dev/null and b/data0/WiredTiger.wt differ
diff --git a/data0/WiredTigerHS.wt b/data0/WiredTigerHS.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data0/WiredTigerHS.wt differ
diff --git a/data0/_mdb_catalog.wt b/data0/_mdb_catalog.wt
new file mode 100644
index 0000000..7d8c6f1
Binary files /dev/null and b/data0/_mdb_catalog.wt differ
diff --git a/data0/collection-0--4349258851694291604.wt b/data0/collection-0--4349258851694291604.wt
new file mode 100644
index 0000000..630cd94
Binary files /dev/null and b/data0/collection-0--4349258851694291604.wt differ
diff --git a/data0/collection-10--4349258851694291604.wt b/data0/collection-10--4349258851694291604.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data0/collection-10--4349258851694291604.wt differ
diff --git a/data0/collection-2--4349258851694291604.wt b/data0/collection-2--4349258851694291604.wt
new file mode 100644
index 0000000..c2c1693
Binary files /dev/null and b/data0/collection-2--4349258851694291604.wt differ
diff --git a/data0/collection-4--4349258851694291604.wt b/data0/collection-4--4349258851694291604.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data0/collection-4--4349258851694291604.wt differ
diff --git a/data0/collection-7--4349258851694291604.wt b/data0/collection-7--4349258851694291604.wt
new file mode 100644
index 0000000..55a78e2
Binary files /dev/null and b/data0/collection-7--4349258851694291604.wt differ
diff --git a/data0/diagnostic.data/metrics.2021-02-04T15-04-45Z-00000 b/data0/diagnostic.data/metrics.2021-02-04T15-04-45Z-00000
new file mode 100644
index 0000000..986a847
Binary files /dev/null and b/data0/diagnostic.data/metrics.2021-02-04T15-04-45Z-00000 differ
diff --git a/data0/diagnostic.data/metrics.2021-02-04T15-11-15Z-00000 b/data0/diagnostic.data/metrics.2021-02-04T15-11-15Z-00000
new file mode 100644
index 0000000..08008a5
Binary files /dev/null and b/data0/diagnostic.data/metrics.2021-02-04T15-11-15Z-00000 differ
diff --git a/data0/diagnostic.data/metrics.2021-02-04T15-18-33Z-00000 b/data0/diagnostic.data/metrics.2021-02-04T15-18-33Z-00000
new file mode 100644
index 0000000..b60d9db
Binary files /dev/null and b/data0/diagnostic.data/metrics.2021-02-04T15-18-33Z-00000 differ
diff --git a/data0/diagnostic.data/metrics.2021-02-04T15-22-05Z-00000 b/data0/diagnostic.data/metrics.2021-02-04T15-22-05Z-00000
new file mode 100644
index 0000000..de59b92
Binary files /dev/null and b/data0/diagnostic.data/metrics.2021-02-04T15-22-05Z-00000 differ
diff --git a/data0/diagnostic.data/metrics.2021-02-04T15-28-16Z-00000 b/data0/diagnostic.data/metrics.2021-02-04T15-28-16Z-00000
new file mode 100644
index 0000000..262a073
Binary files /dev/null and b/data0/diagnostic.data/metrics.2021-02-04T15-28-16Z-00000 differ
diff --git a/data0/diagnostic.data/metrics.2021-02-04T15-33-02Z-00000 b/data0/diagnostic.data/metrics.2021-02-04T15-33-02Z-00000
new file mode 100644
index 0000000..59e975a
Binary files /dev/null and b/data0/diagnostic.data/metrics.2021-02-04T15-33-02Z-00000 differ
diff --git a/data0/diagnostic.data/metrics.interim b/data0/diagnostic.data/metrics.interim
new file mode 100644
index 0000000..d7f131a
Binary files /dev/null and b/data0/diagnostic.data/metrics.interim differ
diff --git a/data0/index-1--4349258851694291604.wt b/data0/index-1--4349258851694291604.wt
new file mode 100644
index 0000000..49027c9
Binary files /dev/null and b/data0/index-1--4349258851694291604.wt differ
diff --git a/data0/index-11--4349258851694291604.wt b/data0/index-11--4349258851694291604.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data0/index-11--4349258851694291604.wt differ
diff --git a/data0/index-3--4349258851694291604.wt b/data0/index-3--4349258851694291604.wt
new file mode 100644
index 0000000..a48dfa4
Binary files /dev/null and b/data0/index-3--4349258851694291604.wt differ
diff --git a/data0/index-5--4349258851694291604.wt b/data0/index-5--4349258851694291604.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data0/index-5--4349258851694291604.wt differ
diff --git a/data0/index-6--4349258851694291604.wt b/data0/index-6--4349258851694291604.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data0/index-6--4349258851694291604.wt differ
diff --git a/data0/index-8--4349258851694291604.wt b/data0/index-8--4349258851694291604.wt
new file mode 100644
index 0000000..bd62105
Binary files /dev/null and b/data0/index-8--4349258851694291604.wt differ
diff --git a/data0/index-9--4349258851694291604.wt b/data0/index-9--4349258851694291604.wt
new file mode 100644
index 0000000..ed0693f
Binary files /dev/null and b/data0/index-9--4349258851694291604.wt differ
diff --git a/data0/journal/WiredTigerPreplog.0000000001 b/data0/journal/WiredTigerPreplog.0000000001
new file mode 100644
index 0000000..aa52a21
Binary files /dev/null and b/data0/journal/WiredTigerPreplog.0000000001 differ
diff --git a/data0/sizeStorer.wt b/data0/sizeStorer.wt
new file mode 100644
index 0000000..bd9038d
Binary files /dev/null and b/data0/sizeStorer.wt differ
diff --git a/data0/storage.bson b/data0/storage.bson
new file mode 100644
index 0000000..276b694
Binary files /dev/null and b/data0/storage.bson differ
diff --git a/data1/WiredTiger b/data1/WiredTiger
new file mode 100644
index 0000000..b7f2a1b
--- /dev/null
+++ b/data1/WiredTiger
@@ -0,0 +1,2 @@
+WiredTiger
+WiredTiger 10.0.0: (March 18, 2020)
diff --git a/data1/WiredTiger.lock b/data1/WiredTiger.lock
new file mode 100644
index 0000000..3d84206
--- /dev/null
+++ b/data1/WiredTiger.lock
@@ -0,0 +1 @@
+WiredTiger lock file
diff --git a/data1/WiredTiger.turtle b/data1/WiredTiger.turtle
new file mode 100644
index 0000000..630277b
--- /dev/null
+++ b/data1/WiredTiger.turtle
@@ -0,0 +1,6 @@
+WiredTiger version string
+WiredTiger 10.0.0: (March 18, 2020)
+WiredTiger version
+major=10,minor=0,patch=0
+file:WiredTiger.wt
+access_pattern_hint=none,allocation_size=4KB,app_metadata=,assert=(commit_timestamp=none,durable_timestamp=none,read_timestamp=none),block_allocation=best,block_compressor=,cache_resident=false,checksum=uncompressed,collator=,columns=,dictionary=0,encryption=(keyid=,name=),format=btree,huffman_value=,id=0,ignore_in_memory_cache_size=false,internal_item_max=0,internal_key_max=0,internal_key_truncate=true,internal_page_max=4KB,key_format=S,key_gap=10,leaf_item_max=0,leaf_key_max=0,leaf_page_max=32KB,leaf_value_max=0,log=(enabled=true),memory_page_image_max=0,memory_page_max=5MB,os_cache_dirty_max=0,os_cache_max=0,prefix_compression=false,prefix_compression_min=4,split_deepen_min_child=0,split_deepen_per_child=0,split_pct=90,value_format=S,version=(major=1,minor=1),checkpoint=(WiredTigerCheckpoint.45=(addr="018381e4b7f568b08481e41f4fdcd18581e48de68736808080e3010fc0e23fc0",order=45,time=1612453684,size=28672,newest_start_durable_ts=0,oldest_start_ts=0,newest_txn=21,newest_stop_durable_ts=0,newest_stop_ts=-1,newest_stop_txn=-11,prepare=0,write_gen=120,run_write_gen=98)),checkpoint_backup_info=,checkpoint_lsn=(8,17920)
diff --git a/data1/WiredTiger.wt b/data1/WiredTiger.wt
new file mode 100644
index 0000000..f689787
Binary files /dev/null and b/data1/WiredTiger.wt differ
diff --git a/data1/WiredTigerHS.wt b/data1/WiredTigerHS.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data1/WiredTigerHS.wt differ
diff --git a/data1/_mdb_catalog.wt b/data1/_mdb_catalog.wt
new file mode 100644
index 0000000..2e85387
Binary files /dev/null and b/data1/_mdb_catalog.wt differ
diff --git a/data1/collection-0-2005600236197793345.wt b/data1/collection-0-2005600236197793345.wt
new file mode 100644
index 0000000..f712b15
Binary files /dev/null and b/data1/collection-0-2005600236197793345.wt differ
diff --git a/data1/collection-10-2005600236197793345.wt b/data1/collection-10-2005600236197793345.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data1/collection-10-2005600236197793345.wt differ
diff --git a/data1/collection-2-2005600236197793345.wt b/data1/collection-2-2005600236197793345.wt
new file mode 100644
index 0000000..8ff591b
Binary files /dev/null and b/data1/collection-2-2005600236197793345.wt differ
diff --git a/data1/collection-4-2005600236197793345.wt b/data1/collection-4-2005600236197793345.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data1/collection-4-2005600236197793345.wt differ
diff --git a/data1/collection-7-2005600236197793345.wt b/data1/collection-7-2005600236197793345.wt
new file mode 100644
index 0000000..233d219
Binary files /dev/null and b/data1/collection-7-2005600236197793345.wt differ
diff --git a/data1/diagnostic.data/metrics.2021-02-04T15-04-45Z-00000 b/data1/diagnostic.data/metrics.2021-02-04T15-04-45Z-00000
new file mode 100644
index 0000000..72e6640
Binary files /dev/null and b/data1/diagnostic.data/metrics.2021-02-04T15-04-45Z-00000 differ
diff --git a/data1/diagnostic.data/metrics.2021-02-04T15-11-16Z-00000 b/data1/diagnostic.data/metrics.2021-02-04T15-11-16Z-00000
new file mode 100644
index 0000000..723c9fc
Binary files /dev/null and b/data1/diagnostic.data/metrics.2021-02-04T15-11-16Z-00000 differ
diff --git a/data1/diagnostic.data/metrics.2021-02-04T15-18-33Z-00000 b/data1/diagnostic.data/metrics.2021-02-04T15-18-33Z-00000
new file mode 100644
index 0000000..41398f0
Binary files /dev/null and b/data1/diagnostic.data/metrics.2021-02-04T15-18-33Z-00000 differ
diff --git a/data1/diagnostic.data/metrics.2021-02-04T15-22-05Z-00000 b/data1/diagnostic.data/metrics.2021-02-04T15-22-05Z-00000
new file mode 100644
index 0000000..b84a7e6
Binary files /dev/null and b/data1/diagnostic.data/metrics.2021-02-04T15-22-05Z-00000 differ
diff --git a/data1/diagnostic.data/metrics.2021-02-04T15-28-16Z-00000 b/data1/diagnostic.data/metrics.2021-02-04T15-28-16Z-00000
new file mode 100644
index 0000000..0b5ab95
Binary files /dev/null and b/data1/diagnostic.data/metrics.2021-02-04T15-28-16Z-00000 differ
diff --git a/data1/diagnostic.data/metrics.2021-02-04T15-33-02Z-00000 b/data1/diagnostic.data/metrics.2021-02-04T15-33-02Z-00000
new file mode 100644
index 0000000..d5f45b3
Binary files /dev/null and b/data1/diagnostic.data/metrics.2021-02-04T15-33-02Z-00000 differ
diff --git a/data1/diagnostic.data/metrics.interim b/data1/diagnostic.data/metrics.interim
new file mode 100644
index 0000000..eb86b02
Binary files /dev/null and b/data1/diagnostic.data/metrics.interim differ
diff --git a/data1/index-1-2005600236197793345.wt b/data1/index-1-2005600236197793345.wt
new file mode 100644
index 0000000..5412d48
Binary files /dev/null and b/data1/index-1-2005600236197793345.wt differ
diff --git a/data1/index-11-2005600236197793345.wt b/data1/index-11-2005600236197793345.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data1/index-11-2005600236197793345.wt differ
diff --git a/data1/index-3-2005600236197793345.wt b/data1/index-3-2005600236197793345.wt
new file mode 100644
index 0000000..44dcd40
Binary files /dev/null and b/data1/index-3-2005600236197793345.wt differ
diff --git a/data1/index-5-2005600236197793345.wt b/data1/index-5-2005600236197793345.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data1/index-5-2005600236197793345.wt differ
diff --git a/data1/index-6-2005600236197793345.wt b/data1/index-6-2005600236197793345.wt
new file mode 100644
index 0000000..3f019cb
Binary files /dev/null and b/data1/index-6-2005600236197793345.wt differ
diff --git a/data1/index-8-2005600236197793345.wt b/data1/index-8-2005600236197793345.wt
new file mode 100644
index 0000000..d8d6517
Binary files /dev/null and b/data1/index-8-2005600236197793345.wt differ
diff --git a/data1/index-9-2005600236197793345.wt b/data1/index-9-2005600236197793345.wt
new file mode 100644
index 0000000..76f0abc
Binary files /dev/null and b/data1/index-9-2005600236197793345.wt differ
diff --git a/data1/sizeStorer.wt b/data1/sizeStorer.wt
new file mode 100644
index 0000000..e885d14
Binary files /dev/null and b/data1/sizeStorer.wt differ
diff --git a/data1/storage.bson b/data1/storage.bson
new file mode 100644
index 0000000..276b694
Binary files /dev/null and b/data1/storage.bson differ
diff --git a/demo-command/pom.xml b/demo-command/pom.xml
index 0096d05..d463b55 100644
--- a/demo-command/pom.xml
+++ b/demo-command/pom.xml
@@ -3,6 +3,13 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
+
+
+ org.springframework.data
+ spring-data-mongodb
+ 3.1.2
+
+
es.dbiosag
diff --git a/demo-command/src/main/java/es/dbiosag/command/domain/model/Phone.java b/demo-command/src/main/java/es/dbiosag/command/domain/model/Phone.java
index adc574c..129e245 100644
--- a/demo-command/src/main/java/es/dbiosag/command/domain/model/Phone.java
+++ b/demo-command/src/main/java/es/dbiosag/command/domain/model/Phone.java
@@ -1,27 +1,20 @@
package es.dbiosag.command.domain.model;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Builder;
import lombok.Data;
-import javax.persistence.*;
+import org.springframework.data.annotation.Id;
@Data
-@Entity
-@Table(name = "PHONES")
@Builder
public class Phone {
@Id
- @GeneratedValue(strategy= GenerationType.AUTO)
- @Column(name = "ID_PHONE")
- private Integer id;
- @Column(name = "NAME")
+ @JsonIgnore
+ private String id;
private String name;
- @Column(name = "MODEL")
private String model;
- @Column(name = "COLOR")
private String color;
- @Column(name = "PRICE")
private Double price;
- @Column(name = "CREATION_DATE")
private String creationDate;
}
diff --git a/demo-command/src/main/java/es/dbiosag/command/domain/service/CreateUserService.java b/demo-command/src/main/java/es/dbiosag/command/domain/service/CreateUserService.java
index 2111e99..61b393e 100644
--- a/demo-command/src/main/java/es/dbiosag/command/domain/service/CreateUserService.java
+++ b/demo-command/src/main/java/es/dbiosag/command/domain/service/CreateUserService.java
@@ -11,8 +11,6 @@ import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import javax.transaction.Transactional;
-
@Service
@Log4j2
public class CreateUserService {
@@ -24,7 +22,6 @@ public class CreateUserService {
@Autowired
private KafkaPhoneCreatedEventSourcing kafkaPhoneCreatedEventSourcing;
- @Transactional
public PhoneCreatedEvent create(CreatePhoneRequest request) {
log.info("Creating new phone");
val phone = phoneConverter.createPhoneRequestRequestToPhone(request);
diff --git a/demo-command/src/main/java/es/dbiosag/command/infrasturcture/repository/PhoneRepository.java b/demo-command/src/main/java/es/dbiosag/command/infrasturcture/repository/PhoneRepository.java
index bd1e4cc..f66f34b 100644
--- a/demo-command/src/main/java/es/dbiosag/command/infrasturcture/repository/PhoneRepository.java
+++ b/demo-command/src/main/java/es/dbiosag/command/infrasturcture/repository/PhoneRepository.java
@@ -1,9 +1,9 @@
package es.dbiosag.command.infrasturcture.repository;
import es.dbiosag.command.domain.model.Phone;
-import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
@Repository
-public interface PhoneRepository extends CrudRepository {
+public interface PhoneRepository extends MongoRepository {
}
diff --git a/demo-command/src/main/resources/ data.sql b/demo-command/src/main/resources/ data.sql
deleted file mode 100644
index b994fc6..0000000
--- a/demo-command/src/main/resources/ data.sql
+++ /dev/null
@@ -1,10 +0,0 @@
-DROP TABLE IF EXISTS phones;
-
-CREATE TABLE phones (
- id_phone INT AUTO_INCREMENT PRIMARY KEY,
- creation_date VARCHAR(250) NOT NULL,
- name VARCHAR(250) NOT NULL,
- model VARCHAR(250) NOT NULL,
- price VARCHAR(250) NOT NULL,
- color VARCHAR(250) NOT NULL
-);
diff --git a/demo-command/src/main/resources/application.yml b/demo-command/src/main/resources/application.yml
index ca46746..677f0f6 100644
--- a/demo-command/src/main/resources/application.yml
+++ b/demo-command/src/main/resources/application.yml
@@ -1,19 +1,16 @@
server:
port: 8081
spring:
- datasource:
- driverClassName: org.h2.Driver
- password: 1234
- url: jdbc:h2:mem:commanddb
- username: sa
- jpa:
- database-platform: org.hibernate.dialect.H2Dialect
- h2:
- console:
- enabled: true
-
+ data:
+ mongodb:
+ authentication-database: examples
+ database: examples
+ username: api_user
+ password: NdEep0XLpMNKUmgQVa81oDCx7mrSRodh0Z79qdX3
+ host: localhost
+ port: 30000
kafka:
- bootstrap-servers: kafka1:9092
+ bootstrap-servers: localhost:29092
consumer:
group-id: test-consumer-group
message:
diff --git a/demo-query/src/main/java/es/dbiosag/query/domain/model/Phone.java b/demo-query/src/main/java/es/dbiosag/query/domain/model/Phone.java
index 1ecca80..0cb0193 100644
--- a/demo-query/src/main/java/es/dbiosag/query/domain/model/Phone.java
+++ b/demo-query/src/main/java/es/dbiosag/query/domain/model/Phone.java
@@ -1,27 +1,19 @@
package es.dbiosag.query.domain.model;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
-
-import javax.persistence.*;
+import org.springframework.data.annotation.Id;
@Data
-@Entity
-@Table(name = "PHONES")
public class Phone {
@Id
- @GeneratedValue(strategy= GenerationType.AUTO)
- @Column(name = "ID_PHONE")
- private Integer id;
- @Column(name = "NAME")
+ @JsonIgnore
+ private String id;
private String name;
- @Column(name = "MODEL")
private String model;
- @Column(name = "COLOR")
private String color;
- @Column(name = "PRICE")
private Double price;
- @Column(name = "CREATION_DATE")
private String creationDate;
public Phone(){ }
diff --git a/demo-query/src/main/java/es/dbiosag/query/domain/service/FindPhoneService.java b/demo-query/src/main/java/es/dbiosag/query/domain/service/FindPhoneService.java
index 7c88133..c9c65b3 100644
--- a/demo-query/src/main/java/es/dbiosag/query/domain/service/FindPhoneService.java
+++ b/demo-query/src/main/java/es/dbiosag/query/domain/service/FindPhoneService.java
@@ -9,8 +9,6 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
-import java.util.Optional;
-
@Service
@Log4j2
public class FindPhoneService {
@@ -21,12 +19,9 @@ public class FindPhoneService {
private PhoneConverter phoneConverter;
public PhoneResponse findByName(String name) throws PhoneNotFoundException {
- Optional phone = phoneRepository.findByName(name);
- if(!phone.isPresent()) {
- throw new PhoneNotFoundException(name, "Phone not found");
- }
+ Phone phone = phoneRepository.findByName(name).orElseThrow(() -> new PhoneNotFoundException(name, "Phone not found"));
log.info("Find phone: {}", phone);
- return phoneConverter.phoneToPhoneResponse(phone.get());
+ return phoneConverter.phoneToPhoneResponse(phone);
}
public void createPhone(Phone p) {
diff --git a/demo-query/src/main/java/es/dbiosag/query/infrastructure/repository/PhoneRepository.java b/demo-query/src/main/java/es/dbiosag/query/infrastructure/repository/PhoneRepository.java
index 6a0aba5..baa5203 100644
--- a/demo-query/src/main/java/es/dbiosag/query/infrastructure/repository/PhoneRepository.java
+++ b/demo-query/src/main/java/es/dbiosag/query/infrastructure/repository/PhoneRepository.java
@@ -1,13 +1,14 @@
package es.dbiosag.query.infrastructure.repository;
import es.dbiosag.query.domain.model.Phone;
-import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Optional;
+
@Repository
-public interface PhoneRepository extends CrudRepository {
+public interface PhoneRepository extends MongoRepository {
Optional findByName(String name);
}
diff --git a/demo-query/src/main/resources/application.yml b/demo-query/src/main/resources/application.yml
index e188c8d..7e6beff 100644
--- a/demo-query/src/main/resources/application.yml
+++ b/demo-query/src/main/resources/application.yml
@@ -1,19 +1,16 @@
server:
port: 8082
spring:
- datasource:
- driverClassName: org.h2.Driver
- password: 1234
- url: jdbc:h2:mem:querydb
- username: sa
- jpa:
- database-platform: org.hibernate.dialect.H2Dialect
- h2:
- console:
- enabled: true
-
+ data:
+ mongodb:
+ authentication-database: examples
+ database: examples
+ username: api_user
+ password: NdEep0XLpMNKUmgQVa81oDCx7mrSRodh0Z79qdX3
+ host: localhost
+ port: 30001
kafka:
- bootstrap-servers: kafka1:9092
+ bootstrap-servers: localhost:29092
consumer:
group-id: test-consumer-group
message:
diff --git a/demo-query/src/main/resources/data.sql b/demo-query/src/main/resources/data.sql
deleted file mode 100644
index b994fc6..0000000
--- a/demo-query/src/main/resources/data.sql
+++ /dev/null
@@ -1,10 +0,0 @@
-DROP TABLE IF EXISTS phones;
-
-CREATE TABLE phones (
- id_phone INT AUTO_INCREMENT PRIMARY KEY,
- creation_date VARCHAR(250) NOT NULL,
- name VARCHAR(250) NOT NULL,
- model VARCHAR(250) NOT NULL,
- price VARCHAR(250) NOT NULL,
- color VARCHAR(250) NOT NULL
-);
diff --git a/docker-compose.yml b/docker-compose.yml
index b939436..9c38b39 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,7 +7,7 @@ services:
ports:
- "2181:2181"
networks:
- - kafka_net
+ - my_network
environment:
ZOO_MY_ID: 1
ZOO_PORT: 2181
@@ -16,6 +16,40 @@ services:
- ./zk-single-kafka-single/zoo1/data:/data
- ./zk-single-kafka-single/zoo1/datalog:/datalog
+ mongo-command:
+ image: mongo:latest
+ container_name: mongo-command
+ hostname: mongo-command
+ environment:
+ MONGO_INITDB_ROOT_USERNAME: root
+ MONGO_INITDB_ROOT_PASSWORD: secret
+ MONGO_INITDB_DATABASE: examples
+ command: ["--bind_ip_all"]
+ ports:
+ - "30000:27017"
+ networks:
+ - my_network
+ volumes:
+ - ./init-mongo.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
+ - ./data0:/data/db
+
+ mongo-query:
+ image: mongo:latest
+ container_name: mongo-query
+ hostname: mongo-query
+ environment:
+ MONGO_INITDB_ROOT_USERNAME: root
+ MONGO_INITDB_ROOT_PASSWORD: secret
+ MONGO_INITDB_DATABASE: examples
+ command: ["--bind_ip_all"]
+ ports:
+ - "30001:27017"
+ networks:
+ - my_network
+ volumes:
+ - ./init-mongo.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
+ - ./data1:/data/db
+
kafka1:
image: confluentinc/cp-kafka:5.5.1
hostname: kafka1
@@ -36,55 +70,13 @@ services:
depends_on:
- zoo1
networks:
- - kafka_net
+ - my_network
healthcheck:
test: [ "CMD", "nc", "-vz", "localhost", "9092" ]
interval: 30s
timeout: 10s
retries: 3
- demo-command:
- build:
- context: .
- dockerfile: Dockerfile
- image: demo-command
- hostname: demo-command
- ports:
- - "8081:8081"
- depends_on:
- kafka1:
- condition: service_healthy
- networks:
- - kafka_net
-
- demo-query-1:
- build:
- context: .
- dockerfile: Dockerfile
- image: demo-query
- hostname: demo-query-1
- ports:
- - "8082:8082"
- depends_on:
- kafka1:
- condition: service_healthy
- networks:
- - kafka_net
-
-# demo-query-2:
-# build:
-# context: demo-query
-# dockerfile: Dockerfile
-# image: demo-query
-# hostname: demo-query-2
-# ports:
-# - "8083:8082"
-# depends_on:
-# kafka1:
-# condition: service_healthy
-# networks:
-# - kafka_net
-
networks:
- kafka_net:
+ my_network:
driver: bridge
diff --git a/init-mongo.js b/init-mongo.js
new file mode 100644
index 0000000..f93193e
--- /dev/null
+++ b/init-mongo.js
@@ -0,0 +1,8 @@
+db.createCollection('examples');
+db.createUser(
+ {
+ user: 'api_user',
+ pwd: 'NdEep0XLpMNKUmgQVa81oDCx7mrSRodh0Z79qdX3',
+ roles: [{ role: 'readWrite', db: 'examples' }],
+ },
+);
diff --git a/pom.xml b/pom.xml
index 7b581d1..ceea50f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,7 +36,7 @@
org.springframework.boot
- spring-boot-starter-data-jpa
+ spring-boot-starter-data-mongodb
org.springframework.kafka