Search code examples
c#masstransitautomatonymousrouting-slipmasstransit-courier

How to monitor MassTransit Courier routing slip properly?


I managed to implement MassTransit Courier routing slip with bunch of activities. I decided to add a state machine to monitor it, so I created separate events and states and used EF Core as a storage for an Automatonymous state machine. To track the current state, I publish an event at the end of execution of each activity. It all works and I can monitor current state of routing slip in the database.

But is it the best way to do it? According to this section in the documentation of MassTransit: https://masstransit-project.com/advanced/courier/events.html it looks like events should be published automatically. So maybe there is another way to monitor routing slip, which does not require creating events and manually publishing them in each activity?


Solution

  • When a routing slip is executing, MassTransit will publish events for each routing slip activity as well as an event once the routing slip has completed.

    You can use those events, rather than creating your own, to monitor the routing slip from start to finish (all events are correlated by TrackingNumber).

    If you have multiple routing slips in your system for different transactions, you can specify subscriptions to route those events directly to the tracking saga for each transaction, instead of publishing, so they don't overlap into separate tracking sagas.

    These events are best used for monitoring/tracking routing slip execution, and should not be used in place of business events. For instance, if your activity charges a credit card, it would make sense to publish a "CreditCardCharged" event with the details for auditing/tracking the card transaction separately for accounting/legal purposes.