Changed to use the Eventuate Java Client
Simplified Spring MVC code since it supports CompletableFuture
This commit is contained in:
@@ -3,12 +3,12 @@ apply plugin: 'java'
|
||||
dependencies {
|
||||
|
||||
compile project(":common-backend")
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import net.chrisrichardson.eventstore.EventUtil;
|
||||
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
|
||||
import io.eventuate.Event;
|
||||
import io.eventuate.EventUtil;
|
||||
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.Command;
|
||||
import io.eventuate.Command;
|
||||
|
||||
interface MoneyTransferCommand extends Command {
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.EventStore;
|
||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
||||
import net.chrisrichardson.eventstore.subscriptions.*;
|
||||
import net.chrisrichardson.eventstore.subscriptions.config.EventStoreSubscriptionsConfiguration;
|
||||
import io.eventuate.AggregateRepository;
|
||||
import io.eventuate.EventuateAggregateStore;
|
||||
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
||||
|
||||
@Configuration
|
||||
@Import(EventStoreSubscriptionsConfiguration.class)
|
||||
@EnableJavaEventHandlers
|
||||
@EnableEventHandlers
|
||||
public class MoneyTransferConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -25,7 +22,7 @@ public class MoneyTransferConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AggregateRepository<MoneyTransfer, MoneyTransferCommand> moneyTransferRepository(EventStore eventStore) {
|
||||
public AggregateRepository<MoneyTransfer, MoneyTransferCommand> moneyTransferRepository(EventuateAggregateStore eventStore) {
|
||||
return new AggregateRepository<MoneyTransfer, MoneyTransferCommand>(MoneyTransfer.class, eventStore);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
||||
import io.eventuate.AggregateRepository;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
|
||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MoneyTransferService {
|
||||
private final AggregateRepository<MoneyTransfer, MoneyTransferCommand> aggregateRepository;
|
||||
@@ -12,7 +13,7 @@ public class MoneyTransferService {
|
||||
this.aggregateRepository = aggregateRepository;
|
||||
}
|
||||
|
||||
public Observable<EntityWithIdAndVersion<MoneyTransfer>> transferMoney(TransferDetails transferDetails) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> transferMoney(TransferDetails transferDetails) {
|
||||
return aggregateRepository.save(new CreateMoneyTransferCommand(transferDetails));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EventHandlerContext;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import io.eventuate.EventHandlerContext;
|
||||
import io.eventuate.EventHandlerMethod;
|
||||
import io.eventuate.EventSubscriber;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitFailedDueToInsufficientFundsEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
||||
import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventHandlerMethod;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventSubscriber;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@EventSubscriber(id="transferEventHandlers")
|
||||
public class MoneyTransferWorkflow implements CompoundEventHandler {
|
||||
public class MoneyTransferWorkflow {
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<?> recordDebit(EventHandlerContext<AccountDebitedEvent> ctx) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordDebit(EventHandlerContext<AccountDebitedEvent> ctx) {
|
||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordDebitCommand());
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<?> recordDebitFailed(EventHandlerContext<AccountDebitFailedDueToInsufficientFundsEvent> ctx) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordDebitFailed(EventHandlerContext<AccountDebitFailedDueToInsufficientFundsEvent> ctx) {
|
||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordDebitFailedCommand());
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<?> recordCredit(EventHandlerContext<AccountCreditedEvent> ctx) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordCredit(EventHandlerContext<AccountCreditedEvent> ctx) {
|
||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordCreditCommand());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user