I've got an event sourced AxonFramework application, which needs to make calls (on/after certain events) to external services. These calls require data from projections, which the event updated/produced.
At first I had the call to the external service and the creation of the projection in the same handler. This assures that the data is persisted and available, but makes it impossible to replay/rebuild the projection, because the external services must not be called again.
Since having the saving of the projection and the service call in the same handler is not an option anymore, I came up with 3 possible solutions:
All 3 come with trade-offs. But I would prefer option 3.
Which one would you choose? Maybe there's an 4th option which I didn't came up with.
Axon allows you to check whether events are being "replayed", or if it's the first time a handler is being called with that particular event.
Basically, you can add a parameter of type ReplayStatus
to your event handler. The isReplay()
method on it will indicate whether the event is part of a replay, or not.
You can find more about this in the documentation: https://docs.axoniq.io/reference-guide/axon-framework/events/event-processors/streaming#replay-api
Ultimately, the best is to entirely separate replayable projections from non-replayable side-effects. In case that's not feasible, the ReplayStatus
parameter is there to help.