whenever this event happens then that even happens

Here’s an excerpt of an event model for an Identity aggregate:

2020-06-03_09-47-45.png

Is this how you would recommend it be implemented?

@Aggregate
class Identity {
  @AggregateIdentifier
  private String accountNumber;
  private String name;
  private int authCode;

  Identity() {}

  @CommandHandler
  Identity(RequestIdentity command) {
    apply(new IdentityRequested(
      command.getAccountNumber(), command.getName(), command.getCell()));
  }

  @EventSourcingHandler
  void on(IdentityRequested event) {
    this.accountNumber = event.getAccountNumber();
    this.name = event.getName();
    this.handleAuthCode(new SendAuthCode(event.getCell()));
  }

  @CommandHandler
  void handleAuthCode(SendAuthCode command) {
    apply(new AuthCodeSent(
      command.getCell(), this.dummyAuthCode()));
  }

  @EventSourcingHandler
  void on(AuthCodeSent event) {
    this.authCode = event.getAuthCode();
  }
  // ...

`

`

Hi Wil,

typically, the purple stickies (policies) are implemented in Axon using Sagas or “plain” event handlers. I would be careful having aggregates communicate directly with each other.
The aggregate as you’ve coded it seems fine. In this implementation, the event “AuthCode Sent” must then be handled by a component that actually sends it. In some domains, this may be confusing, as the audit trail says something happened, but was rather the trigger. An alternative would be to apply a AuthCode Requested. The AuthCode Sent is then emitted by whichever component does the actual interaction with the system that sends these codes.

Hope this helps.
Cheers,

Allard Buijze

CTO

2020-06-03_09-47-45.png