diff --git a/spring-boot/command/pom.xml b/spring-boot/command/pom.xml index 26084d1..b0f64a8 100644 --- a/spring-boot/command/pom.xml +++ b/spring-boot/command/pom.xml @@ -74,12 +74,6 @@ ${esc.version} - - org.fuin.esc - esc-esjc - ${esc.version} - - diff --git a/spring-boot/command/src/main/java/org/fuin/cqrs4j/example/spring/command/app/CmdApplication.java b/spring-boot/command/src/main/java/org/fuin/cqrs4j/example/spring/command/app/CmdApplication.java index b170d14..1c6a957 100644 --- a/spring-boot/command/src/main/java/org/fuin/cqrs4j/example/spring/command/app/CmdApplication.java +++ b/spring-boot/command/src/main/java/org/fuin/cqrs4j/example/spring/command/app/CmdApplication.java @@ -1,77 +1,16 @@ package org.fuin.cqrs4j.example.spring.command.app; -import java.nio.charset.Charset; -import java.util.concurrent.Executors; - -import javax.json.bind.Jsonb; -import javax.json.bind.JsonbBuilder; -import javax.json.bind.JsonbConfig; - -import org.eclipse.yasson.FieldAccessStrategy; import org.fuin.cqrs4j.example.aggregates.PersonRepository; -import org.fuin.cqrs4j.example.shared.SharedUtils; -import org.fuin.cqrs4j.example.spring.shared.Config; -import org.fuin.esc.esjc.ESJCEventStore; import org.fuin.esc.esjc.IESJCEventStore; -import org.fuin.esc.spi.EnhancedMimeType; -import org.fuin.esc.spi.SerDeserializerRegistry; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.web.context.annotation.RequestScope; -import com.github.msemys.esjc.EventStoreBuilder; - @SpringBootApplication(scanBasePackages = { "org.fuin.cqrs4j.example.spring.command.app", "org.fuin.cqrs4j.example.spring.command.controller", "org.fuin.cqrs4j.example.spring.shared" }) public class CmdApplication { - /** - * Creates a Jsonb instance. - * - * @return Fully configured instance. - */ - @Bean - public Jsonb createJsonb() { - final JsonbConfig config = new JsonbConfig().withAdapters(SharedUtils.JSONB_ADAPTERS) - .withPropertyVisibilityStrategy(new FieldAccessStrategy()); - final Jsonb jsonb = JsonbBuilder.create(config); - return jsonb; - } - - /** - * Creates a TCP based event store connection. - * - * @param config Configuration to use. - * - * @return New event store instance. - */ - @Bean(destroyMethod = "shutdown") - public com.github.msemys.esjc.EventStore getESHttpEventStore(final Config config) { - return EventStoreBuilder.newBuilder() - .singleNodeAddress(config.getEventStoreHost(), config.getEventStoreTcpPort()) - .executor(Executors.newFixedThreadPool(10)) - .userCredentials(config.getEventStoreUser(), config.getEventStorePassword()).build(); - } - - /** - * Creates an event store connection. - * - * @param config Configuration to use. - * - * @return New event store instance. - */ - @Bean(destroyMethod = "close") - public IESJCEventStore getEventStore(final com.github.msemys.esjc.EventStore es) { - - final SerDeserializerRegistry registry = SharedUtils.createRegistry(); - final IESJCEventStore eventstore = new ESJCEventStore(es, registry, registry, - EnhancedMimeType.create("application", "json", Charset.forName("utf-8"))); - eventstore.open(); - return eventstore; - - } - /** * Creates an event sourced repository that can store a person. * diff --git a/spring-boot/command/src/main/java/org/fuin/cqrs4j/example/spring/command/controller/PersonController.java b/spring-boot/command/src/main/java/org/fuin/cqrs4j/example/spring/command/controller/PersonController.java index c7d054d..618d51d 100644 --- a/spring-boot/command/src/main/java/org/fuin/cqrs4j/example/spring/command/controller/PersonController.java +++ b/spring-boot/command/src/main/java/org/fuin/cqrs4j/example/spring/command/controller/PersonController.java @@ -12,6 +12,7 @@ */ package org.fuin.cqrs4j.example.spring.command.controller; +import java.util.Optional; import java.util.Set; import javax.validation.ConstraintViolation; @@ -59,7 +60,7 @@ public class PersonController { // Create aggregate final Person person = new Person(cmd.getAggregateRootId(), cmd.getName(), (name) -> { // TODO Execute a call to the query side to verify if the name already exists - return null; + return Optional.empty(); }); repo.add(person); diff --git a/spring-boot/command/src/test/java/org/fuin/cqrs4j/example/spring/command/api/PersonControllerIT.java b/spring-boot/command/src/test/java/org/fuin/cqrs4j/example/spring/command/api/PersonControllerIT.java index 0ae8549..285e594 100644 --- a/spring-boot/command/src/test/java/org/fuin/cqrs4j/example/spring/command/api/PersonControllerIT.java +++ b/spring-boot/command/src/test/java/org/fuin/cqrs4j/example/spring/command/api/PersonControllerIT.java @@ -21,10 +21,10 @@ import org.fuin.cqrs4j.example.shared.PersonId; import org.fuin.cqrs4j.example.shared.PersonName; import org.fuin.cqrs4j.example.spring.command.app.CmdApplication; import org.fuin.esc.api.CommonEvent; -import org.fuin.esc.api.EventStore; import org.fuin.esc.api.SimpleStreamId; import org.fuin.esc.api.StreamEventsSlice; import org.fuin.esc.api.TypeName; +import org.fuin.esc.esjc.IESJCEventStore; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -48,7 +48,7 @@ public class PersonControllerIT { WebApplicationContext wac; @Autowired - EventStore eventStore; + IESJCEventStore eventStore; @Autowired Jsonb jsonb; diff --git a/spring-boot/query/src/main/java/org/fuin/cqrs4j/example/spring/query/views/personlist/PersonListProjector.java b/spring-boot/query/src/main/java/org/fuin/cqrs4j/example/spring/query/views/personlist/PersonListProjector.java index 5cc2a4f..2acfb31 100644 --- a/spring-boot/query/src/main/java/org/fuin/cqrs4j/example/spring/query/views/personlist/PersonListProjector.java +++ b/spring-boot/query/src/main/java/org/fuin/cqrs4j/example/spring/query/views/personlist/PersonListProjector.java @@ -13,9 +13,8 @@ import javax.annotation.PreDestroy; import javax.annotation.concurrent.ThreadSafe; import org.fuin.ddd4j.ddd.EventType; -import org.fuin.esc.api.EventStore; -import org.fuin.esc.api.ProjectionAdminEventStore; import org.fuin.esc.api.TypeName; +import org.fuin.esc.eshttp.IESHttpEventStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -45,10 +44,7 @@ public class PersonListProjector { // Above LOCK prevents multithreaded access @Autowired - private ProjectionAdminEventStore eventstore; - - @Autowired - private EventStore eventStore; + private IESHttpEventStore eventStore; @Autowired private PersonListEventChunkHandler chunkHandler; @@ -93,14 +89,14 @@ public class PersonListProjector { // TODO Make sure a projection with the correct events exists // We must update the projection if new events are defined or some are removed! - if (!eventstore.projectionExists(PROJECTION_STREAM_ID)) { + if (!eventStore.projectionExists(PROJECTION_STREAM_ID)) { final Set eventTypes = dispatcher.getAllTypes(); final List typeNames = new ArrayList<>(); for (final EventType eventType : eventTypes) { typeNames.add(new TypeName(eventType.asBaseType())); } LOG.info("Create projection '{}' with events: {}", PROJECTION_STREAM_ID, typeNames); - eventstore.createProjection(PROJECTION_STREAM_ID, true, typeNames); + eventStore.createProjection(PROJECTION_STREAM_ID, true, typeNames); } // Read and dispatch events diff --git a/spring-boot/query/src/test/java/org/fuin/cqrs4j/example/spring/query/api/PersonControllerIT.java b/spring-boot/query/src/test/java/org/fuin/cqrs4j/example/spring/query/api/PersonControllerIT.java index 1f1958a..9a83b95 100644 --- a/spring-boot/query/src/test/java/org/fuin/cqrs4j/example/spring/query/api/PersonControllerIT.java +++ b/spring-boot/query/src/test/java/org/fuin/cqrs4j/example/spring/query/api/PersonControllerIT.java @@ -23,10 +23,10 @@ import org.fuin.cqrs4j.example.spring.query.views.personlist.PersonListEntry; import org.fuin.cqrs4j.example.spring.shared.Config; import org.fuin.esc.api.CommonEvent; import org.fuin.esc.api.EventId; -import org.fuin.esc.api.EventStore; import org.fuin.esc.api.SimpleCommonEvent; import org.fuin.esc.api.SimpleStreamId; import org.fuin.esc.api.TypeName; +import org.fuin.esc.eshttp.IESHttpEventStore; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -49,7 +49,7 @@ public class PersonControllerIT { WebApplicationContext wac; @Autowired - EventStore eventStore; + IESHttpEventStore eventStore; @Autowired EntityManager em;