@CommandHandler public void handle(TestCommand cmd, CommandGateway gw) { gw.sendAndWait(new Create("1")); try { gw.sendAndWait(new Crash("1")); } catch (RuntimeException e) { System.out.println(e.getMessage()); } gw.sendAndWait(new Hello("1")); }
private void returnDifferenceInBidPriceAndExecutedPrice(long bidPrice, long executedPrice, long amountOfExecutedItems) { long totalDifferenceInCents = amountOfExecutedItems * bidPrice - amountOfExecutedItems * executedPrice; if (totalDifferenceInCents > 0) { commandGateway.send(new CancelCashReservationCommand(portfolioId, transactionId, totalDifferenceInCents)); } } }
@RequestMapping("/debit") @Transactional @ResponseBody public void doDebit(@RequestParam("acc") String accountNumber, @RequestParam("amount") double amount) { DebitAccountCommand debitAccountCommandCommand = new DebitAccountCommand(accountNumber, amount); commandGateway.send(debitAccountCommandCommand); }
@RequestMapping(value = "/api/tasks/{identifier}/complete", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.NO_CONTENT) public void createTask(@PathVariable String identifier) { commandGateway.send(new CompleteTaskCommand(identifier)); }
@Test public void testNoExpectedVersionIgnoresConflicts() { commandGateway.sendAndWait(new CreateCommand("1234")); commandGateway.sendAndWait(new UpdateCommand("1234", "update1", 0L)); commandGateway.sendAndWait(new UpdateCommand("1234", "update1", null)); }
@RequestMapping(value = "/api/tasks/{identifier}/star", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.NO_CONTENT) public void starTask(@PathVariable String identifier) { commandGateway.send(new StarTaskCommand(identifier)); }
@Test public void testNonConflictingEventsAllowed() { commandGateway.sendAndWait(new CreateCommand("1234")); commandGateway.sendAndWait(new UpdateCommand("1234", "update1", 0L)); commandGateway.sendAndWait(new UpdateCommand("1234", "update2", 0L)); }
private void returnDifferenceInBidPriceAndExecutedPrice(long bidPrice, long executedPrice, long amountOfExecutedItems) { long totalDifferenceInCents = amountOfExecutedItems * bidPrice - amountOfExecutedItems * executedPrice; if (totalDifferenceInCents > 0) { commandGateway.send(new CancelCashReservationCommand(portfolioId, transactionId, totalDifferenceInCents)); } } }
@CommandHandler public void handle(Test1 cmd, CommandGateway gw) { gw.sendAndWait(new Add("1", "first")); gw.sendAndWait(new Test2()); }
@RequestMapping(value = "/api/tasks/{identifier}/title", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.NO_CONTENT) public void createTask(@PathVariable String identifier, @RequestBody @Valid ModifyTitleRequest request) { commandGateway.send(new ModifyTaskTitleCommand(identifier, request.getTitle())); }
@CommandHandler public void handle(Test2 cmd, CommandGateway gw) { gw.sendAndWait(new Add("1", "second")); gw.sendAndWait(new ShowItems("1", "pre-rollback")); try { gw.sendAndWait(new Oops()); fail("Command should have failed"); } catch (RuntimeException e) { // expected } gw.sendAndWait(new ShowItems("1", "post-rollback")); }
@RequestMapping(method = RequestMethod.POST) public void create() { LOGGER.info("start"); AccountId id = new AccountId(); LOGGER.debug("Account id: {}", id.toString()); commandGateway.send(new CreateAccountCommand(id, "MyAccount",1000)); commandGateway.send(new WithdrawMoneyCommand(id, 500)); commandGateway.send(new WithdrawMoneyCommand(id, 300)); commandGateway.send(new CreateAccountCommand(id, "MyAccount", 1000)); commandGateway.send(new WithdrawMoneyCommand(id, 500)); } }
@CommandHandler public void handle(Oops cmd, CommandGateway gw) { gw.sendAndWait(new Add("1", "third")); throw new RuntimeException(); } }
@RequestMapping(method = RequestMethod.POST) public void create() { LOGGER.info("start"); AccountId id = new AccountId(); LOGGER.debug("Account id: {}", id.toString()); commandGateway.send(new CreateAccountCommand(id, "MyAccount",1000)); commandGateway.send(new WithdrawMoneyCommand(id, 500)); commandGateway.send(new WithdrawMoneyCommand(id, 300)); /*config.commandBus().dispatch(asCommandMessage(new CreateAccountCommand(id, "MyAccount", 1000))); config.commandBus().dispatch(asCommandMessage(new WithdrawMoneyCommand(id, 500)));*/ } }
@Test public void testUnresolvedConflictCausesException() { commandGateway.sendAndWait(new CreateCommand("1234")); commandGateway.sendAndWait(new UpdateCommand("1234", "update1", 0L)); try { commandGateway.sendAndWait(new UpdateWithoutConflictDetectionCommand("1234", "update2", 0L)); fail("Expected exception"); } catch (ConflictingAggregateVersionException exception) { // success... } }
@RequestMapping(value = "/api/tasks", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.NO_CONTENT) public void createTask(Principal principal, @RequestBody @Valid CreateTaskRequest request) { commandGateway.send(new CreateTaskCommand(identifierFactory.generateIdentifier(), principal.getName(), request.getTitle())); }
@Test public void testExpressedConflictCausesException() { commandGateway.sendAndWait(new CreateCommand("1234")); commandGateway.sendAndWait(new UpdateCommand("1234", "update1", 0L)); try { commandGateway.sendAndWait(new UpdateCommand("1234", "update1", 0L)); fail("Expected exception"); } catch (ConflictingAggregateVersionException exception) { // success... } }
@RequestMapping("/credit") @Transactional @ResponseBody public void doCredit(@RequestParam("acc") String accountNumber, @RequestParam("amount") double amount) { CreditAccountCommand creditAccountCommandCommand = new CreditAccountCommand(accountNumber, amount); GenericCommandMessage<CreditAccountCommand> message = new GenericCommandMessage<>(creditAccountCommandCommand); commandGateway.send(creditAccountCommandCommand, new LoggingCallback(message)); }
@SuppressWarnings("unchecked") @Test public void testInterceptorWithChainProceeding() { commandGateway.sendAndWait(asCommandMessage(new CreateMyAggregateCommand("id"))); commandGateway.sendAndWait(asCommandMessage(new ClearMyAggregateStateCommand("id", true))); ArgumentCaptor<EventMessage<?>> eventCaptor = ArgumentCaptor.forClass(EventMessage.class); verify(eventStore, times(3)).publish(eventCaptor.capture()); assertEquals(new MyAggregateCreatedEvent("id"), eventCaptor.getAllValues().get(0).getPayload()); assertEquals(new AnyCommandInterceptedEvent(ClearMyAggregateStateCommand.class.getName()), eventCaptor.getAllValues().get(1).getPayload()); assertEquals(new MyAggregateStateClearedEvent("id"), eventCaptor.getAllValues().get(2).getPayload()); }
@PostMapping("/rooms/{roomId}/participants") public Future<Void> joinChatRoom(@PathVariable String roomId, @RequestBody @Valid Participant participant) { Assert.notNull(participant.getName(), "name is mandatory for a chatroom"); return commandGateway.send(new JoinRoomCommand(participant.getName(), roomId)); }