sduplooy
sduplooy

Reputation: 14720

How do I execute a routing slip from a saga?

We are using a saga to model a workflow. This workflow waits for events to come in and perform some work based on the events. In some cases, we need to perform multiple tasks (chained .Then methods) one after the other but if one fails we want to compensate the entire chain. Routing slips seem appropriate but I'm not sure if such a routing slip can be executed from a Then method in a saga?

Upvotes: 3

Views: 1510

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33278

It is possible, and quite common actually, to execute a routing slip from behavior within a state machine saga. It is recommended, however, that a command be sent from the saga to a regular consumer which then builds and executes the routing slip.

A separate state machine can then monitor the progress of the routing slip, using the routing slip events to move the state forward. Once the routing slip is completed, a business event can be produced by the routing slip state machine which is observed by the original saga to either move forward (in the case of success) or transition to a failure state (if the routing slip faults).

By having a separate state machine for the routing slip, it is then possible to add things like scheduled retries which can add resilience to the business transaction modeled by the routing slip activities. It also keeps the concerns of the routing slip separate, and keeps the original saga clean using only business events.

There is a good demo of this available as well: https://github.com/phatboyg/Demo-Registration

Upvotes: 4

Related Questions