Implementing own SagaManager

Hi Folks,

I’m curently thinking and discussing with some guys the ability to externalize the execution of Saga out of Axon.

In general we are evaluating the usage of a flow-models for BASE transactions as used in orchestration scenarios with self-contained systems. Many platforms offer solutions for this problems. Axon uses Sagas, AWS uses StepFunctions, Spring uses Spring Cloud Data Flow etc. This approaches have some drawbacks regarding readability and get pretty complex in scenarios with compensation. In doing so, I’m evaluating a possibility to delegate the Saga execution to a process engine, which can execute BASE transactions modelled as BPMN 2.x. BPMN 2.x is very powerful in modeling orchestration and has well-defined concepts for transaction, messaging and compensation and is wide adopted in the industry by developers and business people.

The Saga will then not be a annotated Java class, but rather a configuration mapping of the Axon events to BPMN 2.x signals and the engine will be interacting with the EventBus / CommandBus infrastructure to drive the transaction.
There are several possibilities to do so:

  1. The simpliest is to register own MessageConsumer, delegating all events to a component that quits Axon infrastructure and does everything on its own.

  2. In the same time, I’m very interesting in keeping Axon Saga at place, but just delegating the execution of the event handler to external component. My goal is to get it running first and then try to create a generic delegating component suitable for all Sagas with the configuration of event mapping. This will also include the storage of Saga internal state not in the Axon infrastructure, but in external process variables inside of the process engine.

As far as I understood the code, I’ll need to implemement a different Saga Manager for that which would do the delegation instead of the current execution.

Some questions so far:

  • Do you think the replacement of Saga Manager is a correct/intended approach?

  • Would I just register a let’s say “MySagaManager” and return it instead of a Subsrcibing / Tracking Saga Manager using the SagaConfiguration?

  • I’m a little locked in the code, since SagaConfiguration needs to be returned, but it has a private constructor and the only factory methods create Tracking/Subscribing SagaConfiguration with a Hard-Coded annotated SagaManager at place. Any ideas how I can by-pass this?

  • If there are no ways to bypass this, what will be the interface I want to implement to “simulate” SagaManager interaction? Does it mean I have to go with 1) instead of 2) ?

Kind regards,

Simon

Hi Simon,

let me answer the Configuration-related question first, as it’s an easier one to get out of the way: the SagaConfiguration class is intended to make Configuration of Axon’s Saga components easier. If you build a different component, you could use the ModuleConfiguration interface to hook into the Configuration lifecycle, but you can also just configure it using the components provided by the Configuration instance.

The idea of using BPMN for Sagas is one that I’ve been playing around with for a long time as well. Conceptually, it seems to fit quite nicely with the Sagas. As you said, you would use events to trigger transitions in the BPMN engine.

Your best hook into AxonFramework is most likely the interface that the SagaManager also uses: EventHandlerInvoker. Alternatively, what also might work, is implementing the AbstractSagaManager class, and creating a JbpmSagaRepository to load instances based on association values.

If you just implement EventHandlerInvoker, you would receive an Event, load process instances based on some identifiers (association values?) and trigger the processes.

Hope this helps.
Cheers,

Allard