Hi Sandeep, Aditya,
I would suggest against calling external services from within Event Sourcing Handlers at all times.
The Event Sourcing Handler is intended to “source a given command model from the events itself has published”, and nothing else.
If you want to react to events, you will have to write a (singleton) Event Handling Component.
Axon will ensure your Event Handling Component will be backed by an Event Processor, which by default is a Tracking Event Processor (TEP for short).
Note that the TEP provides you the option to replay the events, to for example recreate Query Models.
It is suggested not to replay an Event Handling Function which introduces side effects like calling an external service.
How to deal with conditionally performing some operations when you issue a replay against a Tracking Event Processor, I suggest you to read this page of the Reference Guide.
Lastly, note that you can only have a single Event Handling Function for a given event in one class.
Thus duplicating said Event Handler in the same implementation will not make the framework call both.
Concluding, yes you can conditionally perform operations in Event Sourcing Handlers.
For this you can ask the AggregateLifecycle whether ‘it is live’, which you could have found here in the Reference Guide.
However, as said earlier, I strongly suggest against performing any kind of external service calls from within an Aggregate, ever.
Hope this clarifies things for you.
Cheers,
Steven van Beelen
Axon Framework Lead Developer
AxonIQ
Axon in Action Award 2019 - Nominate your project

