Design question (external call) for command handler on aggregate

So I set up a IntervalRetryScheduler on certain non-AxonNonTransientException. The retry is doing what it is supposed to do, i.e. reprocess the command from the beginning. The issue is my aggregate command handler makes soap call, which is being invoked second time now. This soap call is not (can not be) managed by spring transaction which axon’s unit of work is utilizing.

How to better design this? Where should I invoke the soap call which should not be invoked twice? In EventHandler? This must have been encountered by other people. Thanks for the insight in advance.

I guess the real questions is: from where to invoke external call? Should I do the call inside command handler or by publishing an event and let event handler to do? Is it ok to issue another command inside a command handler? (Are they in the same transaction?). There are just so many options to choose, wonder which is the best.

I think I got the answer. Introduce a intermediate state and use a new event to advance the aggregate state. That makes the external call not part of the transaction.

It seems to me that what you require is a Saga, that’s what should store your ‘intermediate state’. I haven’t upgraded to Axon 4 yet so I may be a bit out of date, but it seems to me that you’re trying to perform orchestration in response to a Command, when you should be performing orchestration in a Saga in response to meaningful domain events. For example, you can wrap your SOAP call in a try-catch so that if a failure occurs, you can publish a ‘…Failed’ event and handle it accordingly. If that seems like too much trouble you can also just perform the request last and let an unchecked exception roll back Axon’s transaction, though this may not be best- as I’ve observed this behaviour in Axon 3.4 but I don’t know if it’s guaranteed in the future.

Not an employee Axon but HTH.