Starting a Saga conditionally

Hi Axon users

My team is in a situation where we have the same service running twice, but for 2 different locations.
Both services receive all events from each other. The events have a ‘tenant id’ in their payload which contains the location. Based on this tenant id, each event listener knows to ONLY listen for it’s own location.

The problem we face involves the starting of Sagas. We want to be able to start a Saga only if the starting event has the tenant id for its own location. We know you can conditionally close a Saga, but the conditionally starting of a Saga doesn’t seem to be possible.
A possible solution would be to start the Saga, then check if the tenant equals the location of the service, and close the Saga if the condition is not fulfilled. However this doesn’t seem to be very clean to us.

Does anybody have an idea to do this properly?

Thanks in advance.

I think you can raise an event conditionally, can you?

Hi Gert,

in your case, you might be best off using a MessageHandlerInterceptor on the SagaManager or on the Event Processor. This interceptor allows you to prevent execution of an event by simply not calling ‘chain.proceed()’ and returning an arbitrary value (e.g. null).

Hope this helps.


Hi Allard

this indeed did help, thanks a lot!

Gert Berckvens