What I’m guessing your’e doing, is trying to add an ‘event sourcing handler’ to your Account Aggregate which handlers your snapshot-events.
Is that a correct assumption?
If so, the answer to your question is simple.
You only need to handle snapshot events, if you’re not using an AggregateSnapshotter.
As you’re using the SpringAggregateSnapshotterFactoryBean, you will end up with a SpringAggregetSnapshotter, which is an implementation of an AggregateSnapshotter.
You’ll thus end up with AggregateSnapshot instances, which you do not have to handle yourself.
An AggregateSnapshot is technically a serialized version of your Aggregate.
Hello, Steven. How are you doing?
Thanks for the answer btw.
"You’ll thus end up with AggregateSnapshot instances, which you do not have to handle yourself. An AggregateSnapshot is technically a serialized version of your Aggregate."
I understand this and that’s how I’m using right now.
But let I try to explain this better. I saw this piece of code
@EventHandler
protected void applySnapshot(MySnapshotEvent event) {
// the snapshot event should contain all relevant state
this.someState = event.someState;
this.otherState = event.otherState;
}
at the documentation and I really like the idea of having my own snapshot event bean: MySnapshotEvent, in this case.
I think makes things more clear special with this method name “applySnapshot” even tho I have to write more code.
So I dug deep in the source code and I didn’t figure out how to take a snapshot with a custom event like that instead of Aggregate itself.
Ah, sorry for that! I thought the internals were unclear, but I apparently made too quick an assumption.
To answer your questions though, I think you should be able to create a Snapshotter which sets a different payload type if you’d want to.
I’d probably start off with the AbstractSnapshotter myself, and introduce an implementation which sets the desired payload type i.o. using the Aggregate type.
That said though, it would require some additional engineering, as the framework currently doesn’t easily support you changing the payload type.
I hope this helps Mike, feel free to further this discussion if necessary!