Rollback an event sourced aggregate to n-1st version

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.

public class Document {

private String id;

private String content.

public void reject(RejectCommand command) {

public void on(RejectEvent event) {
// Rollback to n-1st version of this aggregate.
// this.content = howToRetrieve(n-1).content ???


Cheers, Rajesh

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.