Start saga from a command/DTO

All,

We have a use case where

  • a user enters a lot of data in one screen
  • a single backend service accepts this data in the form of a DTO
  • this starts a business process (Saga) during which a set of aggregates needs to be created

How can we implement this in Axon: the business process here starts at the backend service (with the DTO containing all the data) where the sagas in axon start from events.

One option would be to translate the DTO to a command and let it handle by one aggregate resulting in an event containing all the data that was in the DTO.
Then the saga can kick in based on that event and create the other aggregates.

Downside of this approach is that the first event contains a lot of data that actually does not belong to the aggregate…

I would prefer to start a Saga directly from the backend service. Is this possible in Axon?

Regards,
Robin

Hi Robin,

You should be able to use an autowired EventBus directly to achieve that.
If you perform an eventBus.publish with an event holding all your DTO data and have an eventhandler (@SagaEventHandler) in your Saga annotated with @StartSaga, you should be up and running!

Do you mean that axon framework support to start a saga by just publishing an event on the EventGateway from anywhere in our applications? (from an aggregate or a service or a @RestController or etc)

Yes it does. The origin of an event is completely irrelevant for an Event Handler. Any component can publish an event on the bus.

Be careful with naming these events, though. Typically, events that have a technical focus, rather than describing something on the business level, are often a sign of a design mistake.

Cheers,

Allard

twitter-icon_128x128.png