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

794 views
Skip to first unread message

Richard Valdivieso

unread,
Mar 18, 2017, 11:54:00 AM3/18/17
to Axon Framework Users
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


jorgheymans

unread,
Mar 18, 2017, 3:35:36 PM3/18/17
to Axon Framework Users
You could set a status flag to 'deleted.

Richard Valdivieso

unread,
Mar 18, 2017, 10:20:05 PM3/18/17
to axonfr...@googlegroups.com
Thanks. I will try that.

Richard

On Mar 18, 2017 3:35 PM, "jorgheymans" <jorg.h...@gmail.com> wrote:
You could set a status flag to 'deleted.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/mQVGN6AMwco/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframework+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Allard Buijze

unread,
Mar 19, 2017, 2:45:00 AM3/19/17
to axonfr...@googlegroups.com
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
Op zo 19 mrt. 2017 om 03:20 schreef Richard Valdivieso <richardva...@gmail.com>
Thanks. I will try that.

Richard

On Mar 18, 2017 3:35 PM, "jorgheymans" <jorg.h...@gmail.com> wrote:
You could set a status flag to 'deleted.

--
You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/mQVGN6AMwco/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframewor...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.

Richard Valdivieso

unread,
Mar 20, 2017, 7:02:10 AM3/20/17
to Axon Framework Users
Thanks Allard

Richard
Reply all
Reply to author
Forward
0 new messages