Rollback an event sourced aggregate to n-1st version

90 views
Skip to first unread message

Rajesh Retnasamy

unread,
Jul 24, 2017, 11:02:25 AM7/24/17
to Axon Framework Users
I've a requirement to rollback to the n-1st version of the event sourced aggregate upon reception of reject command. I'm using spring boot to bring up axon engine. I've searched the group and found few relevant discussions but there is no sample code snippet to implement this. Please take me to the axon class/document explaining it - thanks.


@Aggregate
public class Document {

@AggregateIdentifier
private String id;

private String content.

.....
@CommandHandler 
public void reject(RejectCommand command) {
     apply(RejectEvent.id(command.id).build);
}
...
@EventSourcingHandler
public void on(RejectEvent event) {
    // Rollback to n-1st version of this aggregate.
    // this.content = howToRetrieve(n-1).content ???
}

}

Cheers, Rajesh

Steven van Beelen

unread,
Jul 27, 2017, 4:45:42 AM7/27/17
to Axon Framework Users
Hi Rajesh,

So, upon a certain command being handle by your aggregate, you want to load the previous state of that aggregate?
The way you've thought of it isn't the approach to take I'd say.

What you probably want to do, is make a reverting action for every event which has been applied to that aggregate after N-1.
This is also not a thing I'd do in the aggregate, but rather in the service which now publishes the described RejectCommand.
The service would in this scenario check which event have been applied to that aggregate after N-1 and create 'rejecting-commands' for each of those events.

Doing the revert/reject in one big bang would also enforce all your query side event handlers to know how to deal with such a complete revert (something I'd say is probably tough to do); one of the reasons why a finer grained solution like a propose above seems safer to me.

Hope this helps.

Cheers,

Steven


--
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.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages