Start saga from a command/DTO

331 views
Skip to first unread message

Robin Custers

unread,
Jun 26, 2017, 3:22:34 AM6/26/17
to Axon Framework Users
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

Frank Groot

unread,
Jun 26, 2017, 5:03:37 AM6/26/17
to Axon Framework Users
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!



--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Frank Groot - Lead Architect - frank...@trifork.nl - http://www.trifork.nl/ 
Mobile: +31 6 5073 1421 Office: +31 20 486 20 36 Fax: +31 20 475 08 28
Address: 
Rijnsburgstraat 9-11 1059 AT - Amsterdam - The Netherlands

Yoann CAPLAIN

unread,
Nov 22, 2019, 12:37:27 AM11/22/19
to Axon Framework Users

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)

Le lundi 26 juin 2017 17:03:37 UTC+8, Frank Groot a écrit :
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!



On Mon, Jun 26, 2017 at 9:22 AM Robin Custers <robin....@gmail.com> wrote:
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

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonfr...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Allard Buijze

unread,
Nov 24, 2019, 10:21:54 PM11/24/19
to axonfr...@googlegroups.com
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

To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/axonframework/1bac005a-0e1c-46f1-bd03-2d4166915bc9%40googlegroups.com.
--
Allard Buijze
CTO

 twitter-icon_128x128.png
Reply all
Reply to author
Forward
0 new messages