Axon 3. How is the proper way to use a delete event handler

Hello everybody

I have something like this for an update command:

@CommandHandler
public void handle(AccountUpdateCommand command) {
    AccountUpdatedEvent event = new AccountUpdatedEvent(command.getAccountEventId(), command.getAccountId(), command.getFirstName(), command.getLastName(), command.getPhone());
    apply(event);
}

@EventSourcingHandler
protected void on(AccountSavedEvent event) {
    this.accountEventId = event.getAccountEventId();
    this.firstName = event.getFirstName();
    this.lastName = event.getLastName();
    this.email = event.getEmail();

}

But how would be the best way to reflect a delete using an event:

@CommandHandler
public void handle(AccountUpdateCommand command) {
    AccountDeleteEvent event = new AccountDeleteEvent(command.getAccountEventId(), command.getAccountId(), command.getFirstName(), command.getLastName(), command.getPhone());
    apply(event);
}

@EventSourcingHandler
protected void on(AccountDeleteEvent event) {
   ????????

}

Could anyone help me, please?

Thanks in advance

Richard

You could set a status flag to 'deleted.

Thanks. I will try that.

Richard

Use AggregateLifcycle.markDeleted() in your @EventSourcingHandler to mark it as deleted. Axon will throw AggregateDeletedException (extends AggregateNotFoundException) when attemptong to load it from repository.

Cheers,

Allard

Thanks Allard

Richard