Fixed problems

This commit is contained in:
Michael Schnell
2019-12-31 08:38:03 +01:00
parent eb71c77197
commit d2bfe20577
6 changed files with 10 additions and 80 deletions

View File

@@ -74,12 +74,6 @@
<version>${esc.version}</version>
</dependency>
<dependency>
<groupId>org.fuin.esc</groupId>
<artifactId>esc-esjc</artifactId>
<version>${esc.version}</version>
</dependency>
<!-- runtime -->
<dependency>

View File

@@ -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.
*

View File

@@ -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);

View File

@@ -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;

View File

@@ -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<EventType> eventTypes = dispatcher.getAllTypes();
final List<TypeName> 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

View File

@@ -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;