Search code examples
c#entity-framework-coremasstransitstate-machinesaga

Querying MassTransit State Machine information


Is it OK to use the DbContext used by MassTransit to store the StateMachines as a regular DbContext?

In my application we want to implement the following scenario (removed validation and err handling):

  • A queue request comes in through an asp.net mvc api
  • The request gets published by MassTransit. The correlation id is returned as response
  • The request gets split in N smaller requests
  • They smaller requests get handled in parallell
  • If all the smaller requests are finished the main request is handled

The progress and status of the queue request should be queryable through the api.

If I read the docs correctly this is what StateMachine and Saga are used for. The saga is working and tested, but now I want to implement the part where I can query the state information.

Should I use the EFCore DbContext that is used as persistance for MassTransit as a regular DbContext?
Is there an existing way to better communicate this data store is not for writing outside masstransit? Is there a better way to interrogate a StateMachine or Saga?


Solution

  • A DbContext is just that, there isn't anything special about it. So, you can certainly use it to query status. There are also other options to query status from a saga state machine using request/response. Various examples cover these details.

    From your description, I'd suggest looking at Sample-Batch which seems to do something similar to what you're trying to accomplish.