@CommandHandler public void handle(DebitSourceBankAccountCommand command) { try { Aggregate<BankAccount> bankAccountAggregate = repository.load(command.getBankAccountId()); bankAccountAggregate.execute(bankAccount -> bankAccount .debit(command.getAmount(), command.getBankTransferId())); } catch (AggregateNotFoundException exception) { eventBus.publish(asEventMessage(new SourceBankAccountNotFoundEvent(command.getBankTransferId()))); } }
@CommandHandler public void handle(CreditDestinationBankAccountCommand command) { try { Aggregate<BankAccount> bankAccountAggregate = repository.load(command.getBankAccountId()); bankAccountAggregate.execute(bankAccount -> bankAccount .credit(command.getAmount(), command.getBankTransferId())); } catch (AggregateNotFoundException exception) { eventBus.publish(asEventMessage(new DestinationBankAccountNotFoundEvent(command.getBankTransferId()))); } } }