Changed to use the Eventuate Java Client

Simplified Spring MVC code since it supports CompletableFuture
This commit is contained in:
Chris Richardson
2016-05-16 06:27:47 -07:00
parent c5778b1379
commit 4b3fe001e7
73 changed files with 290 additions and 531 deletions

View File

@@ -27,7 +27,7 @@ fi
export SERVICE_HOST=$DOCKER_HOST_IP
./gradlew $* build
./gradlew $* build -x :e2e-test:test
if [ -z "$EVENTUATE_API_KEY_ID" -o -z "$EVENTUATE_API_KEY_SECRET" ] ; then
echo You must set EVENTUATE_API_KEY_ID and EVENTUATE_API_KEY_SECRET

View File

@@ -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"
}

View File

@@ -1,8 +1,8 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
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.accounts.AccountCreditedEvent;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitFailedDueToInsufficientFundsEvent;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;

View File

@@ -1,6 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
import net.chrisrichardson.eventstore.Command;
import io.eventuate.Command;
interface AccountCommand extends Command {
}

View File

@@ -1,13 +1,13 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
import net.chrisrichardson.eventstore.EventStore;
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
import net.chrisrichardson.eventstore.repository.AggregateRepository;
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;
@Configuration
@EnableJavaEventHandlers
@EnableEventHandlers
public class AccountConfiguration {
@Bean
@@ -22,7 +22,7 @@ public class AccountConfiguration {
}
@Bean
public AggregateRepository<Account, AccountCommand> accountRepository(EventStore eventStore) {
public AggregateRepository<Account, AccountCommand> accountRepository(EventuateAggregateStore eventStore) {
return new AggregateRepository<Account, AccountCommand>(Account.class, eventStore);
}

View File

@@ -1,10 +1,12 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
import net.chrisrichardson.eventstore.repository.AggregateRepository;
import io.eventuate.AggregateRepository;
import io.eventuate.EntityWithIdAndVersion;
import java.math.BigDecimal;
import java.util.concurrent.CompletableFuture;
public class AccountService {
@@ -14,7 +16,7 @@ public class AccountService {
this.accountRepository = accountRepository;
}
public rx.Observable<EntityWithIdAndVersion<Account>> openAccount(BigDecimal initialBalance) {
public CompletableFuture<EntityWithIdAndVersion<Account>> openAccount(BigDecimal initialBalance) {
return accountRepository.save(new OpenAccountCommand(initialBalance));
}

View File

@@ -1,34 +1,36 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
import net.chrisrichardson.eventstore.EntityIdentifier;
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.transactions.DebitRecordedEvent;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent;
import net.chrisrichardson.eventstore.subscriptions.*;
import rx.Observable;
import java.math.BigDecimal;
import java.util.concurrent.CompletableFuture;
@EventSubscriber(id="accountEventHandlers")
public class AccountWorkflow implements CompoundEventHandler {
public class AccountWorkflow {
@EventHandlerMethod
public Observable<?> debitAccount(EventHandlerContext<MoneyTransferCreatedEvent> ctx) {
public CompletableFuture<EntityWithIdAndVersion<Account>> debitAccount(EventHandlerContext<MoneyTransferCreatedEvent> ctx) {
MoneyTransferCreatedEvent event = ctx.getEvent();
BigDecimal amount = event.getDetails().getAmount();
EntityIdentifier transactionId = ctx.getEntityIdentifier();
String transactionId = ctx.getEntityId();
EntityIdentifier fromAccountId = event.getDetails().getFromAccountId();
String fromAccountId = event.getDetails().getFromAccountId();
return ctx.update(Account.class, fromAccountId, new DebitAccountCommand(amount, transactionId));
}
@EventHandlerMethod
public Observable<?> creditAccount(EventHandlerContext<DebitRecordedEvent> ctx) {
public CompletableFuture<EntityWithIdAndVersion<Account>> creditAccount(EventHandlerContext<DebitRecordedEvent> ctx) {
DebitRecordedEvent event = ctx.getEvent();
BigDecimal amount = event.getDetails().getAmount();
EntityIdentifier fromAccountId = event.getDetails().getToAccountId();
EntityIdentifier transactionId = ctx.getEntityIdentifier();
String fromAccountId = event.getDetails().getToAccountId();
String transactionId = ctx.getEntityId();
return ctx.update(Account.class, fromAccountId, new CreditAccountCommand(amount, transactionId));
}

View File

@@ -1,15 +1,15 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.EntityIdentifier;
import io.eventuate.Aggregate;
import java.math.BigDecimal;
public class CreditAccountCommand implements AccountCommand {
private final BigDecimal amount;
private final EntityIdentifier transactionId;
private final String transactionId;
public CreditAccountCommand(BigDecimal amount, EntityIdentifier transactionId) {
public CreditAccountCommand(BigDecimal amount, String transactionId) {
this.amount = amount;
this.transactionId = transactionId;
@@ -19,7 +19,7 @@ public class CreditAccountCommand implements AccountCommand {
return amount;
}
public EntityIdentifier getTransactionId() {
public String getTransactionId() {
return transactionId;
}
}

View File

@@ -1,15 +1,15 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.EntityIdentifier;
import io.eventuate.Aggregate;
import java.math.BigDecimal;
public class DebitAccountCommand implements AccountCommand {
private final BigDecimal amount;
private final EntityIdentifier transactionId;
private final String transactionId;
public DebitAccountCommand(BigDecimal amount, EntityIdentifier transactionId) {
public DebitAccountCommand(BigDecimal amount, String transactionId) {
this.amount = amount;
this.transactionId = transactionId;
@@ -19,7 +19,7 @@ public class DebitAccountCommand implements AccountCommand {
return amount;
}
public EntityIdentifier getTransactionId() {
public String getTransactionId() {
return transactionId;
}
}

View File

@@ -1,7 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
import net.chrisrichardson.eventstore.CommandProcessingAggregates;
import net.chrisrichardson.eventstore.Event;
import io.eventuate.Event;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
import org.junit.Assert;
import org.junit.Test;
@@ -15,7 +14,7 @@ public class AccountTest {
public void testSomething() {
Account account = new Account();
BigDecimal initialBalance = new BigDecimal(512);
List<Event> events = CommandProcessingAggregates.processToList(account, (AccountCommand)new OpenAccountCommand(initialBalance));
List<Event> events = account.process(new OpenAccountCommand(initialBalance));
Assert.assertEquals(1, events.size());
Assert.assertEquals(AccountOpenedEvent.class, events.get(0).getClass());

View File

@@ -11,7 +11,7 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
testCompile "org.springframework.boot:spring-boot-starter-test"

View File

@@ -1,6 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web;
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
import io.eventuate.javaclient.httpstomp.spring.EventuateHttpStompClientConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@Configuration
@Import({CommandSideWebAccountsConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
@Import({CommandSideWebAccountsConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
@EnableAutoConfiguration
@ComponentScan
public class AccountsCommandSideServiceConfiguration {

View File

@@ -6,7 +6,7 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
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"
}

View File

@@ -7,7 +7,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import rx.Observable;
import java.util.concurrent.CompletableFuture;
@RestController
@RequestMapping("/accounts")
@@ -21,8 +22,8 @@ public class AccountController {
}
@RequestMapping(method = RequestMethod.POST)
public Observable<CreateAccountResponse> createAccount(@Validated @RequestBody CreateAccountRequest request) {
public CompletableFuture<CreateAccountResponse> createAccount(@Validated @RequestBody CreateAccountRequest request) {
return accountService.openAccount(request.getInitialBalance())
.map(entityAndEventInfo -> new CreateAccountResponse(entityAndEventInfo.getEntityIdentifier().getId()));
.thenApply(entityAndEventInfo -> new CreateAccountResponse(entityAndEventInfo.getEntityId()));
}
}

View File

@@ -1,34 +1,16 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import java.util.ArrayList;
import java.util.List;
@Configuration
@Import({AccountConfiguration.class})
@ComponentScan
@EnableAutoConfiguration
public class CommandSideWebAccountsConfiguration extends WebMvcConfigurerAdapter {
public class CommandSideWebAccountsConfiguration {
class FakeThing {}
@Bean
public FakeThing init(RequestMappingHandlerAdapter adapter) {
// https://jira.spring.io/browse/SPR-13083
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
handlers.add(0, new ObservableReturnValueHandler());
adapter.setReturnValueHandlers(handlers);
return new FakeThing();
}
}

View File

@@ -1,11 +1,11 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({CommandSideWebAccountsConfiguration.class, JdbcEventStoreConfiguration.class})
@Import({CommandSideWebAccountsConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
public class AccountControllerIntegrationTestConfiguration {
}

View File

@@ -3,17 +3,13 @@ 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"
compile "org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion"
compile 'com.fasterxml.jackson.core:jackson-core:2.4.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.4.3'
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"
}

View File

@@ -1,9 +1,8 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.EntityNotFoundException;
import rx.Observable;
import io.eventuate.CompletableFutureUtil;
import java.util.concurrent.CompletableFuture;
public class AccountQueryService {
@@ -13,11 +12,11 @@ public class AccountQueryService {
this.accountInfoRepository = accountInfoRepository;
}
public Observable<AccountInfo> findByAccountId(EntityIdentifier accountId) {
AccountInfo account = accountInfoRepository.findOne(accountId.getId());
public CompletableFuture<AccountInfo> findByAccountId(String accountId) {
AccountInfo account = accountInfoRepository.findOne(accountId);
if (account == null)
return Observable.error(new AccountNotFoundException(accountId.getId()));
return CompletableFutureUtil.failedFuture(new AccountNotFoundException(accountId));
else
return Observable.just(account);
return CompletableFuture.completedFuture(account);
}
}

View File

@@ -1,17 +1,15 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
import net.chrisrichardson.eventstore.EntityIdentifier;
import io.eventuate.DispatchedEvent;
import io.eventuate.EventHandlerMethod;
import io.eventuate.EventSubscriber;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountChangedEvent;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent;
import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler;
import net.chrisrichardson.eventstore.subscriptions.DispatchedEvent;
import net.chrisrichardson.eventstore.subscriptions.EventHandlerMethod;
import net.chrisrichardson.eventstore.subscriptions.EventSubscriber;
import rx.Observable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,7 +18,7 @@ import java.math.BigDecimal;
import static net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.MoneyUtil.toIntegerRepr;
@EventSubscriber(id="querySideEventHandlers")
public class AccountQueryWorkflow implements CompoundEventHandler {
public class AccountQueryWorkflow {
private Logger logger = LoggerFactory.getLogger(getClass());
@@ -31,58 +29,55 @@ public class AccountQueryWorkflow implements CompoundEventHandler {
}
@EventHandlerMethod
public Observable<Object> create(DispatchedEvent<AccountOpenedEvent> de) {
AccountOpenedEvent event = de.event();
String id = de.getEntityIdentifier().getId();
String eventId = de.eventId().asString();
public void create(DispatchedEvent<AccountOpenedEvent> de) {
AccountOpenedEvent event = de.getEvent();
String id = de.getEntityId();
String eventId = de.getEventId().asString();
logger.info("**************** account version=" + id + ", " + eventId);
BigDecimal initialBalance = event.getInitialBalance();
accountInfoUpdateService.create(id, initialBalance, eventId);
return Observable.just(null);
}
@EventHandlerMethod
public Observable<Object> recordTransfer(DispatchedEvent<MoneyTransferCreatedEvent> de) {
String eventId = de.eventId().asString();
String moneyTransferId = de.getEntityIdentifier().getId();
String fromAccountId = de.event().getDetails().getFromAccountId().getId();
String toAccountId = de.event().getDetails().getToAccountId().getId();
logger.info("**************** account version=" + fromAccountId + ", " + de.eventId().asString());
logger.info("**************** account version=" + toAccountId + ", " + de.eventId().asString());
public void recordTransfer(DispatchedEvent<MoneyTransferCreatedEvent> de) {
String eventId = de.getEventId().asString();
String moneyTransferId = de.getEntityId();
String fromAccountId = de.getEvent().getDetails().getFromAccountId();
String toAccountId = de.getEvent().getDetails().getToAccountId();
logger.info("**************** account version=" + fromAccountId + ", " + de.getEventId().asString());
logger.info("**************** account version=" + toAccountId + ", " + de.getEventId().asString());
AccountTransactionInfo ti = new AccountTransactionInfo(moneyTransferId, fromAccountId, toAccountId, toIntegerRepr(de.event().getDetails().getAmount()));
AccountTransactionInfo ti = new AccountTransactionInfo(moneyTransferId, fromAccountId, toAccountId, toIntegerRepr(de.getEvent().getDetails().getAmount()));
accountInfoUpdateService.addTransaction(eventId, fromAccountId, ti);
accountInfoUpdateService.addTransaction(eventId, toAccountId, ti);
return Observable.just(null);
}
@EventHandlerMethod
public Observable<Object> recordDebit(DispatchedEvent<AccountDebitedEvent> de) {
return saveChange(de, -1);
public void recordDebit(DispatchedEvent<AccountDebitedEvent> de) {
saveChange(de, -1);
}
@EventHandlerMethod
public Observable<Object> recordCredit(DispatchedEvent<AccountCreditedEvent> de) {
return saveChange(de, +1);
public void recordCredit(DispatchedEvent<AccountCreditedEvent> de) {
saveChange(de, +1);
}
public <T extends AccountChangedEvent> Observable<Object> saveChange(DispatchedEvent<T> de, int delta) {
String changeId = de.eventId().asString();
String transactionId = de.event().getTransactionId().getId();
long amount = toIntegerRepr(de.event().getAmount());
public <T extends AccountChangedEvent> void saveChange(DispatchedEvent<T> de, int delta) {
String changeId = de.getEventId().asString();
String transactionId = de.getEvent().getTransactionId();
long amount = toIntegerRepr(de.getEvent().getAmount());
long balanceDelta = amount * delta;
AccountChangeInfo ci = new AccountChangeInfo(changeId, transactionId, de.event().getClass().getSimpleName(), amount, balanceDelta);
String accountId = de.getEntityIdentifier().getId();
logger.info("**************** account version=" + accountId + ", " + de.eventId().asString());
AccountChangeInfo ci = new AccountChangeInfo(changeId, transactionId, de.getEvent().getClass().getSimpleName(), amount, balanceDelta);
String accountId = de.getEntityId();
logger.info("**************** account version=" + accountId + ", " + de.getEventId().asString());
accountInfoUpdateService.updateBalance(accountId, changeId, balanceDelta, ci);
return Observable.just(null);
}

View File

@@ -1,7 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
import io.eventuate.javaclient.spring.EnableEventHandlers;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
@@ -9,7 +9,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
@Configuration
@EnableMongoRepositories
@EnableJavaEventHandlers
@EnableEventHandlers
public class QuerySideAccountConfiguration {
@Bean

View File

@@ -3,8 +3,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.ac
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import rx.Observable;
import rx.Subscriber;
import javax.annotation.PostConstruct;
import java.util.concurrent.TimeUnit;
@@ -22,17 +20,7 @@ public class QuerySideDependencyChecker {
try {
logger.info("Checking mongodb connectivity {}", System.getenv("SPRING_DATA_MONGODB_URI"));
Observable.<Object>create(new Observable.OnSubscribe<Object>() {
@Override
public void call(Subscriber<? super Object> subscriber) {
try {
subscriber.onNext(mongoTemplate.getDb().getCollectionNames());
subscriber.onCompleted();
} catch (Throwable t) {
subscriber.onError(t);
}
}
}).timeout(5, TimeUnit.SECONDS).toBlocking().first();
mongoTemplate.getDb().getCollectionNames();
} catch (Throwable e) {
throw new RuntimeException("Error connecting to Mongo - have you set SPRING_DATA_MONGODB_URI or --spring.data.mongodb_uri?", e);

View File

@@ -10,7 +10,7 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
testCompile project(":testutil")
testCompile "org.springframework.boot:spring-boot-starter-test"

View File

@@ -1,6 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web;
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
import io.eventuate.javaclient.httpstomp.spring.EventuateHttpStompClientConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@Configuration
@Import({QuerySideWebConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
@Import({QuerySideWebConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
@EnableAutoConfiguration
@ComponentScan
public class AccountsQuerySideServiceConfiguration {

View File

@@ -13,10 +13,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal;
import java.util.concurrent.CompletableFuture;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
import rx.Observable;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
@@ -51,8 +51,8 @@ public class AccountsQuerySideServiceIntegrationTest {
eventually(
new Producer<GetAccountResponse>() {
@Override
public Observable<GetAccountResponse> produce() {
return Observable.just(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
public CompletableFuture<GetAccountResponse> produce() {
return CompletableFuture.completedFuture(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
}
},
new Verifier<GetAccountResponse>() {

View File

@@ -1,36 +1,14 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.QuerySideAccountConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Bean;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
@Configuration
@Import({QuerySideAccountConfiguration.class})
@ComponentScan
public class QuerySideWebConfiguration extends WebMvcConfigurerAdapter {
public class QuerySideWebConfiguration {
class FakeThing {}
@Bean
public FakeThing init(RequestMappingHandlerAdapter adapter) {
// https://jira.spring.io/browse/SPR-13083
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
handlers.add(0, new ObservableReturnValueHandler());
adapter.setReturnValueHandlers(handlers);
return new FakeThing();
}
}

View File

@@ -1,14 +1,14 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountNotFoundException;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import rx.Observable;
import java.math.BigDecimal;
import java.util.concurrent.CompletableFuture;
@RestController
public class AccountQueryController {
@@ -21,9 +21,9 @@ public class AccountQueryController {
}
@RequestMapping(value="/accounts/{accountId}", method = RequestMethod.GET)
public Observable<GetAccountResponse> get(@PathVariable String accountId) {
return accountInfoQueryService.findByAccountId(new EntityIdentifier(accountId))
.map(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance())));
public CompletableFuture<GetAccountResponse> get(@PathVariable String accountId) {
return accountInfoQueryService.findByAccountId(accountId)
.thenApply(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance())));
}
@ResponseStatus(value= HttpStatus.NOT_FOUND, reason="account not found")

View File

@@ -8,6 +8,6 @@ dependencies {
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"
}

View File

@@ -1,14 +1,13 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import net.chrisrichardson.utils.config.MetricRegistryConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, JdbcEventStoreConfiguration.class})
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
public class BankingTestConfiguration {
}

View File

@@ -1,14 +1,13 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
import net.chrisrichardson.eventstore.EntityWithMetadata;
import net.chrisrichardson.eventstore.EventStore;
import io.eventuate.EntityWithIdAndVersion;
import io.eventuate.EventuateAggregateStore;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.TransferState;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -16,12 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import rx.Observable;
import java.math.BigDecimal;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.await;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
@@ -38,7 +34,7 @@ public class MoneyTransferIntegrationTest {
private MoneyTransferService moneyTransferService;
@Autowired
private EventStore eventStore;
private EventuateAggregateStore eventStore;
@Test
@@ -48,52 +44,22 @@ public class MoneyTransferIntegrationTest {
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
toAccount.getEntityIdentifier(),
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
toAccount.getEntityId(),
new BigDecimal(80))));
eventually (
new Producer<EntityWithMetadata<Account>>() {
@Override
public Observable<EntityWithMetadata<Account>> produce() {
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, fromAccount.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<Account>>() {
@Override
public void verify(EntityWithMetadata<Account> account) {
Assert.assertEquals(new BigDecimal(70), account.entity().getBalance());
}
});
() -> eventStore.find(Account.class, fromAccount.getEntityId()),
account -> Assert.assertEquals(new BigDecimal(70), account.getEntity().getBalance()));
eventually (
new Producer<EntityWithMetadata<Account>>() {
@Override
public Observable<EntityWithMetadata<Account>> produce() {
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, toAccount.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<Account>>() {
@Override
public void verify(EntityWithMetadata<Account> account) {
Assert.assertEquals(new BigDecimal(380), account.entity().getBalance());
}
});
() -> eventStore.find(Account.class, toAccount.getEntityId()),
account -> Assert.assertEquals(new BigDecimal(380), account.getEntity().getBalance()));
eventually (
new Producer<EntityWithMetadata<MoneyTransfer>>() {
@Override
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
return (Observable<EntityWithMetadata<MoneyTransfer>>)eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
@Override
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.entity().getState());
}
});
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
}
@Test
@@ -103,52 +69,22 @@ public class MoneyTransferIntegrationTest {
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
toAccount.getEntityIdentifier(),
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
toAccount.getEntityId(),
new BigDecimal(200))));
eventually (
new Producer<EntityWithMetadata<MoneyTransfer>>() {
@Override
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
return (Observable<EntityWithMetadata<MoneyTransfer>>)eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
@Override
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
Assert.assertEquals(TransferState.FAILED_DUE_TO_INSUFFICIENT_FUNDS, updatedTransaction.entity().getState());
}
});
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
updatedTransaction -> Assert.assertEquals(TransferState.FAILED_DUE_TO_INSUFFICIENT_FUNDS, updatedTransaction.getEntity().getState()));
eventually (
new Producer<EntityWithMetadata<Account>>() {
@Override
public Observable<EntityWithMetadata<Account>> produce() {
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, fromAccount.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<Account>>() {
@Override
public void verify(EntityWithMetadata<Account> account) {
Assert.assertEquals(new BigDecimal(150), account.entity().getBalance());
}
});
() -> eventStore.find(Account.class, fromAccount.getEntityId()),
account -> Assert.assertEquals(new BigDecimal(150), account.getEntity().getBalance()));
eventually (
new Producer<EntityWithMetadata<Account>>() {
@Override
public Observable<EntityWithMetadata<Account>> produce() {
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, toAccount.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<Account>>() {
@Override
public void verify(EntityWithMetadata<Account> account) {
Assert.assertEquals(new BigDecimal(300), account.entity().getBalance());
}
});
() -> eventStore.find(Account.class, toAccount.getEntityId()),
account -> Assert.assertEquals(new BigDecimal(300), account.getEntity().getBalance()));
}

View File

@@ -1,8 +1,8 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
import net.chrisrichardson.eventstore.EntityWithMetadata;
import net.chrisrichardson.eventstore.EventStore;
import io.eventuate.EntityWithIdAndVersion;
import io.eventuate.EntityWithMetadata;
import io.eventuate.EventuateAggregateStore;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
@@ -37,7 +37,7 @@ public class AccountQuerySideIntegrationTest {
private MoneyTransferService moneyTransferService;
@Autowired
private EventStore eventStore;
private EventuateAggregateStore eventStore;
@Autowired
private AccountQueryService accountQueryService;
@@ -50,49 +50,19 @@ public class AccountQuerySideIntegrationTest {
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount(new BigDecimal(300)));
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
toAccount.getEntityIdentifier(),
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
toAccount.getEntityId(),
new BigDecimal(80))));
eventually(
new Producer<EntityWithMetadata<MoneyTransfer>>() {
@Override
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
return eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
}
},
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
@Override
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.entity().getState());
}
});
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
eventually(
new Producer<AccountInfo>() {
@Override
public Observable<AccountInfo> produce() {
return accountQueryService.findByAccountId(fromAccount.getEntityIdentifier());
}
},
new Verifier<AccountInfo>() {
@Override
public void verify(AccountInfo accountInfo) {
Assert.assertEquals(70*100, accountInfo.getBalance());
}
});
() -> accountQueryService.findByAccountId(fromAccount.getEntityId()),
accountInfo -> Assert.assertEquals(70*100, accountInfo.getBalance()));
eventually(
new Producer<AccountInfo>() {
@Override
public Observable<AccountInfo> produce() {
return accountQueryService.findByAccountId(toAccount.getEntityIdentifier());
}
},
new Verifier<AccountInfo>() {
@Override
public void verify(AccountInfo accountInfo) {
Assert.assertEquals(380*100, accountInfo.getBalance());
}
});
() -> accountQueryService.findByAccountId(toAccount.getEntityId()),
accountInfo -> Assert.assertEquals(380*100, accountInfo.getBalance()));
}
}

View File

@@ -1,14 +1,15 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideAccountConfiguration.class})
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class,
QuerySideAccountConfiguration.class})
@EnableAutoConfiguration
public class AccountQuerySideTestConfiguration {
}

View File

@@ -1,11 +1,11 @@
apply plugin: 'java'
dependencies {
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
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"
}

View File

@@ -1,16 +1,16 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.Event;
import io.eventuate.Aggregate;
import io.eventuate.Event;
import java.math.BigDecimal;
public class AccountChangedEvent implements Event {
protected BigDecimal amount;
protected EntityIdentifier transactionId;
protected String transactionId;
public AccountChangedEvent(BigDecimal amount, EntityIdentifier transactionId) {
public AccountChangedEvent(BigDecimal amount, String transactionId) {
this.amount = amount;
this.transactionId = transactionId;
}
@@ -18,7 +18,7 @@ public class AccountChangedEvent implements Event {
public AccountChangedEvent() {
}
public EntityIdentifier getTransactionId() {
public String getTransactionId() {
return transactionId;
}

View File

@@ -1,7 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.EntityIdentifier;
import io.eventuate.Aggregate;
import java.math.BigDecimal;
@@ -10,7 +10,7 @@ public class AccountCreditedEvent extends AccountChangedEvent {
private AccountCreditedEvent() {
}
public AccountCreditedEvent(BigDecimal amount, EntityIdentifier transactionId) {
public AccountCreditedEvent(BigDecimal amount, String transactionId) {
super(amount, transactionId);
}

View File

@@ -1,20 +1,20 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.Event;
import io.eventuate.Aggregate;
import io.eventuate.Event;
public class AccountDebitFailedDueToInsufficientFundsEvent implements Event {
private EntityIdentifier transactionId;
private String transactionId;
private AccountDebitFailedDueToInsufficientFundsEvent() {
}
public AccountDebitFailedDueToInsufficientFundsEvent(EntityIdentifier transactionId) {
public AccountDebitFailedDueToInsufficientFundsEvent(String transactionId) {
this.transactionId = transactionId;
}
public EntityIdentifier getTransactionId() {
public String getTransactionId() {
return transactionId;
}
}

View File

@@ -1,7 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.EntityIdentifier;
import io.eventuate.Aggregate;
import java.math.BigDecimal;
@@ -10,7 +10,7 @@ public class AccountDebitedEvent extends AccountChangedEvent {
private AccountDebitedEvent() {
}
public AccountDebitedEvent(BigDecimal amount, EntityIdentifier transactionId) {
public AccountDebitedEvent(BigDecimal amount, String transactionId) {
super(amount, transactionId);
}

View File

@@ -1,7 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
import net.chrisrichardson.eventstore.Event;
import io.eventuate.Event;
import java.math.BigDecimal;

View File

@@ -1,2 +1,2 @@
@net.chrisrichardson.eventstore.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account")
@io.eventuate.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account")
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;

View File

@@ -1,6 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
import net.chrisrichardson.eventstore.Event;
import io.eventuate.Event;
public class CreditRecordedEvent implements Event {
private TransferDetails details;

View File

@@ -1,6 +1,8 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
import net.chrisrichardson.eventstore.Event;
// import io.eventuate.Event;
import io.eventuate.Event;
public class DebitRecordedEvent implements Event {
private TransferDetails details;

View File

@@ -1,6 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
import net.chrisrichardson.eventstore.Event;
import io.eventuate.Event;
public class FailedDebitRecordedEvent implements Event {
private TransferDetails details;

View File

@@ -1,7 +1,7 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
import net.chrisrichardson.eventstore.Event;
import io.eventuate.Event;
public class MoneyTransferCreatedEvent implements Event {
private TransferDetails details;

View File

@@ -1,33 +1,33 @@
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
/*
case class TransferDetails(fromAccountId : EntityIdentifier, toAccountId : EntityIdentifier, amount : BigDecimal)
case class TransferDetails(fromAccountId : String, toAccountId : String, amount : BigDecimal)
*/
import net.chrisrichardson.eventstore.EntityIdentifier;
import java.math.BigDecimal;
public class TransferDetails {
private EntityIdentifier fromAccountId;
private EntityIdentifier toAccountId;
private String fromAccountId;
private String toAccountId;
private BigDecimal amount;
private TransferDetails() {
}
public TransferDetails(EntityIdentifier fromAccountId, EntityIdentifier toAccountId, BigDecimal amount) {
public TransferDetails(String fromAccountId, String toAccountId, BigDecimal amount) {
this.fromAccountId = fromAccountId;
this.toAccountId = toAccountId;
this.amount = amount;
}
public EntityIdentifier getFromAccountId() {
public String getFromAccountId() {
return fromAccountId;
}
public EntityIdentifier getToAccountId() {
public String getToAccountId() {
return toAccountId;
}

View File

@@ -1,2 +1,2 @@
@net.chrisrichardson.eventstore.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer")
@io.eventuate.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer")
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;

View File

@@ -1,9 +1,8 @@
package net.chrisrichardson.eventstore.javaexamples.banking.common.accounts;
import io.eventuate.javaclient.commonimpl.JSonMapper;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
import net.chrisrichardson.eventstore.json.EventStoreCommonObjectMapping;
import net.chrisrichardson.utils.json.JSonMapper;
import org.junit.Assert;
import org.junit.Test;
@@ -14,10 +13,10 @@ public class AccountOpenEventSerializationTest {
@Test
public void shouldSerde() {
AccountOpenedEvent event = new AccountOpenedEvent(new BigDecimal(55));
String json = JSonMapper.toJson(event, EventStoreCommonObjectMapping.getObjectMapper());
String json = JSonMapper.toJson(event);
System.out.println("json=" + json);
AccountOpenedEvent event2 = JSonMapper.fromJSon(AccountOpenedEvent.class, json, EventStoreCommonObjectMapping.getObjectMapper());
AccountOpenedEvent event2 = JSonMapper.fromJson(json, AccountOpenedEvent.class);
Assert.assertEquals(event.getInitialBalance(), event2.getInitialBalance());
}

View File

@@ -1,5 +1,5 @@
dependencies {
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
compile "io.springfox:springfox-swagger2:2.2.2"
compile 'io.springfox:springfox-swagger-ui:2.2.2'

View File

@@ -6,14 +6,14 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import org.springframework.web.context.request.async.DeferredResult;
import rx.Observable;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.WildcardType;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.concurrent.CompletableFuture;
import static springfox.documentation.schema.AlternateTypeRules.newRule;
@Configuration
@@ -27,7 +27,7 @@ public class CommonSwaggerConfiguration {
.apis(RequestHandlerSelectors.basePackage("net.chrisrichardson.eventstore.javaexamples.banking"))
.build()
.pathMapping("/")
.genericModelSubstitutes(ResponseEntity.class, Observable.class)
.genericModelSubstitutes(ResponseEntity.class, CompletableFuture.class)
.alternateTypeRules(
newRule(typeResolver.resolve(DeferredResult.class,
typeResolver.resolve(ResponseEntity.class, WildcardType.class)),

View File

@@ -1,7 +1,7 @@
apply plugin: 'java'
dependencies {
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
testCompile "junit:junit:4.11"

View File

@@ -1,33 +0,0 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.util;
import org.springframework.web.context.request.async.DeferredResult;
import rx.Observable;
import rx.Subscriber;
import java.util.concurrent.atomic.AtomicReference;
public class DeferredUtils {
public static <T> DeferredResult<T> toDeferredResult(Observable<T> o) {
final DeferredResult<T> d = new DeferredResult<T>();
final AtomicReference<T> r = new AtomicReference<T>();
o.single().subscribe(new Subscriber<T>() {
@Override
public void onCompleted() {
d.setResult(r.get());
}
@Override
public void onError(Throwable e) {
d.setErrorResult(e);
}
@Override
public void onNext(T t) {
r.set(t);
}
});
return d;
}
}

View File

@@ -1,31 +0,0 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.util;
import rx.Observable;
import org.springframework.core.MethodParameter;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.context.request.async.WebAsyncUtils;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
public class ObservableReturnValueHandler implements HandlerMethodReturnValueHandler {
@Override
public boolean supportsReturnType(MethodParameter returnType) {
return Observable.class.equals(returnType.getParameterType());
}
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
if (returnValue == null) {
return;
}
DeferredResult<?> d = DeferredUtils.toDeferredResult((Observable<?>) returnValue);
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(d, mavContainer);
}
}

View File

@@ -1,8 +1,6 @@
apply plugin: VerifyMongoDBConfigurationPlugin
dependencies {
compile "org.scala-lang:scala-library:2.10.2"
testCompile project(":accounts-command-side-web")
testCompile project(":transactions-command-side-web")
testCompile project(":accounts-query-side-web")
@@ -10,8 +8,6 @@ dependencies {
testCompile project(":testutil")
testCompile "junit:junit:4.11"
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
testCompile scalaTestDependency
}
test {

View File

@@ -6,17 +6,14 @@ import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accou
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferRequest;
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferResponse;
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts.GetAccountResponse;
import net.chrisrichardson.eventstore.json.EventStoreCommonObjectMapping;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import rx.Observable;
import java.math.BigDecimal;
import java.util.concurrent.CompletableFuture;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
@@ -43,14 +40,14 @@ public class EndToEndTest {
RestTemplate restTemplate = new RestTemplate();
{
/*{
for (HttpMessageConverter<?> mc : restTemplate.getMessageConverters()) {
if (mc instanceof MappingJackson2HttpMessageConverter) {
((MappingJackson2HttpMessageConverter) mc).setObjectMapper(EventStoreCommonObjectMapping.getObjectMapper());
((MappingJackson2HttpMessageConverter) mc).setObjectMapper(JSonMapper.objectMapper);
}
}
}
}*/
@Test
@@ -92,18 +89,10 @@ public class EndToEndTest {
private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) {
final BigDecimal inCents = toCents(expectedBalanceInDollars);
eventually(
new Producer<GetAccountResponse>() {
@Override
public Observable<GetAccountResponse> produce() {
return Observable.just(restTemplate.getForEntity(accountsQuerySideBaseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
}
},
new Verifier<GetAccountResponse>() {
@Override
public void verify(GetAccountResponse accountInfo) {
Assert.assertEquals(fromAccountId, accountInfo.getAccountId());
Assert.assertEquals(inCents, accountInfo.getBalance());
}
() -> CompletableFuture.completedFuture(restTemplate.getForEntity(accountsQuerySideBaseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody()),
accountInfo -> {
Assert.assertEquals(fromAccountId, accountInfo.getAccountId());
Assert.assertEquals(inCents, accountInfo.getBalance());
});
}

View File

@@ -1,10 +1,9 @@
org.gradle.jvmargs=-XX:MaxPermSize=512m
eventuateMavenRepoUrl=http://mavenrepo.eventuate.io/release
eventuateMavenRepoUrl=file:///Users/cer/.m2/testdeploy
scalaTestDependency=org.scalatest:scalatest_2.10:2.0
springBootVersion=1.3.5.RELEASE
springBootVersion=1.2.8.RELEASE
eventuateClientVersion=0.1.0-SNAPSHOT
eventStoreClientVersion=0.12

View File

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.0-all.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-2.11-all.zip

View File

@@ -10,7 +10,7 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
compile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
testCompile project(":testutil")
testCompile "org.springframework.boot:spring-boot-starter-test"

View File

@@ -1,9 +1,9 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web;
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
@@ -14,7 +14,7 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@Configuration
@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class})
@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, EventuateJdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class})
@EnableAutoConfiguration
@ComponentScan
public class BankingWebConfiguration {

View File

@@ -17,10 +17,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal;
import java.util.concurrent.CompletableFuture;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
import rx.Observable;
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
@@ -78,18 +78,10 @@ public class BankingWebIntegrationTest {
private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) {
final BigDecimal inCents = toCents(expectedBalanceInDollars);
eventually(
new Producer<GetAccountResponse>() {
@Override
public Observable<GetAccountResponse> produce() {
return Observable.just(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
}
},
new Verifier<GetAccountResponse>() {
@Override
public void verify(GetAccountResponse accountInfo) {
Assert.assertEquals(fromAccountId, accountInfo.getAccountId());
Assert.assertEquals(inCents, accountInfo.getBalance());
}
() -> CompletableFuture.completedFuture(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody()),
accountInfo -> {
Assert.assertEquals(fromAccountId, accountInfo.getAccountId());
Assert.assertEquals(inCents, accountInfo.getBalance());
});
}

View File

@@ -1,15 +1,13 @@
apply plugin: 'java'
dependencies {
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
compile 'com.fasterxml.jackson.core:jackson-core:2.4.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.4.3'
compile "junit:junit:4.11"
compile "io.reactivex:rxjava:1.1.5"
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"
}

View File

@@ -1,10 +1,10 @@
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
import net.chrisrichardson.eventstore.Aggregate;
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
import net.chrisrichardson.eventstore.subscriptions.EventEntityUtil;
import org.springframework.util.ReflectionUtils;
import io.eventuate.Aggregate;
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
import io.eventuate.javaclient.spring.EventEntityUtil;
import org.junit.Test;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;
@@ -17,19 +17,15 @@ public abstract class AbstractEntityEventTest {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
Class eventClass = method.getParameterTypes()[0];
String entityClassName = EventEntityUtil.entityClassFor(eventClass);
try {
Class.forName(entityClassName);
} catch (ClassNotFoundException e) {
throw new RuntimeException("for " + entityClassName, e);
}
EventEntityUtil.toEntityType(eventClass);
}
},
new ReflectionUtils.MethodFilter() {
@Override
public boolean matches(Method method) {
return method.getName().startsWith("apply") && method.getDeclaringClass() != Aggregate.class && method.getDeclaringClass() != ReflectiveMutableCommandProcessingAggregate.class;
return method.getName().startsWith("apply") &&
method.getDeclaringClass() != Aggregate.class &&
method.getDeclaringClass() != ReflectiveMutableCommandProcessingAggregate.class;
}
});

View File

@@ -1,7 +1,7 @@
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
import rx.Observable;
import java.util.concurrent.CompletableFuture;
public interface Producer<T> {
public Observable<T> produce();
public CompletableFuture<T> produce();
}

View File

@@ -1,16 +1,25 @@
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.functions.Func2;
import rx.internal.operators.OnSubscribeRefCount;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class TestUtil {
public static <T> T await(Observable<T> o) {
return o.single().timeout(1, TimeUnit.SECONDS).toBlocking().getIterator().next();
public static <T> T await(CompletableFuture<T> o) {
try {
return o.get(1, TimeUnit.SECONDS);
} catch (InterruptedException | TimeoutException | ExecutionException e) {
throw new RuntimeException(e);
}
}
@@ -52,7 +61,7 @@ public class TestUtil {
@Override
public Observable<Outcome<T>> call(Long aLong) {
try {
return producer.produce().map(new Func1<T, Outcome<T>>() {
return fromCompletableFuture(producer.produce()).map(new Func1<T, Outcome<T>>() {
@Override
public Outcome<T> call(T t) {
return new Success<T>(t);
@@ -92,4 +101,21 @@ public class TestUtil {
throw new RuntimeException((Throwable)possibleException);
}
private static <T> Observable<T> fromCompletableFuture(CompletableFuture<T> future) {
return Observable.create(new Observable.OnSubscribe<T>() {
@Override
public void call(Subscriber<? super T> subscriber) {
future.handle((result, throwable) -> {
if (throwable != null)
subscriber.onError(throwable);
else {
subscriber.onNext(result);
subscriber.onCompleted();
}
return null;
});
}
});
}
}

View File

@@ -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"
}

View File

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

View File

@@ -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 {
}

View File

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

View File

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

View File

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

View File

@@ -9,7 +9,7 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
testCompile "org.springframework.boot:spring-boot-starter-test"

View File

@@ -1,6 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web;
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
import io.eventuate.javaclient.httpstomp.spring.EventuateHttpStompClientConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
@Configuration
@Import({CommandSideWebTransactionsConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
@Import({CommandSideWebTransactionsConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
@EnableAutoConfiguration
@ComponentScan
public class TransactionsCommandSideServiceConfiguration {

View File

@@ -6,7 +6,7 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
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"
}

View File

@@ -1,36 +1,13 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Bean;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
@Configuration
@Import({MoneyTransferConfiguration.class})
@ComponentScan
public class CommandSideWebTransactionsConfiguration extends WebMvcConfigurerAdapter {
class FakeThing {}
@Bean
public FakeThing init(RequestMappingHandlerAdapter adapter) {
// https://jira.spring.io/browse/SPR-13083
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
handlers.add(0, new ObservableReturnValueHandler());
adapter.setReturnValueHandlers(handlers);
return new FakeThing();
}
public class CommandSideWebTransactionsConfiguration {
}

View File

@@ -1,6 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
import org.springframework.beans.factory.annotation.Autowired;
@@ -9,7 +9,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import rx.Observable;
import java.util.concurrent.CompletableFuture;
@RestController
@RequestMapping("/transfers")
@@ -23,13 +24,13 @@ public class MoneyTransferController {
}
@RequestMapping(method = RequestMethod.POST)
public Observable<CreateMoneyTransferResponse> createMoneyTransfer(@Validated @RequestBody CreateMoneyTransferRequest request) {
public CompletableFuture<CreateMoneyTransferResponse> createMoneyTransfer(@Validated @RequestBody CreateMoneyTransferRequest request) {
TransferDetails transferDetails = new TransferDetails(
new EntityIdentifier(request.getFromAccountId()),
new EntityIdentifier(request.getToAccountId()),
request.getFromAccountId(),
request.getToAccountId(),
request.getAmount());
return moneyTransferService.transferMoney(transferDetails)
.map(entityAndEventInfo -> new CreateMoneyTransferResponse(entityAndEventInfo.getEntityIdentifier().getId()));
.thenApply(entityAndEventInfo -> new CreateMoneyTransferResponse(entityAndEventInfo.getEntityIdAndVersion().getEntityId()));
}
}

View File

@@ -1,12 +1,12 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class})
@Import({CommandSideWebTransactionsConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
@EnableAutoConfiguration
public class MoneyTransferControllerIntegrationTestConfiguration {
}