Search code examples
masstransitsaga

How to configure MassTransit Saga to use several custom named topics?


I have a Saga that receives a command from the queue, sends a command to another queue, transitions to another state and waits for an event from the topic the name of which is custom (not named by MassTransit as an event type name). I am having a problem that Saga doesn't react to the event from custom named topic.

The Saga does the following:

  1. Receive a command from the queue.

     cfg.ReceiveEndpoint("submit-order-queue", configureEndpoint =>
     {
         configureEndpoint.ConfigureSaga<OrderShipmentState>(context);
         configureEndpoint.RequiresSession = true;
    });
    
  2. Send a command to another queue and transition to another state. I am using a custom activity.

  3. Consume an event from a topic. The topic name needs to be specified.

     cfg.SubscriptionEndpoint(
           "subsctiption1", "custom-name-topic", 
            configure =>
            {
                 configure.ConfigureSaga<OrderShipmentState>(context);
            });
    

I found a couple of similar questions like this with an answer from Chris Patterson

If you want to use a subscription endpoint for a saga, you would need to configure the saga on the corresponding topic for each event.

I tried to achieve this with the code above but I haven't figured out how to specify the event in the configuration above. The method below will not work for me as I need to specify the custom topic name:

void SubscriptionEndpoint<T>(string subscriptionName, Action<IServiceBusSubscriptionEndpointConfigurator> configure) where T : class;

In the result, I am able to execute the 1st and 2nd steps, but on the 3rd step I get an event in the ASB subscription but the Saga doesn't react to that event.

Any suggestions what I am doing wrong?


Solution

  • In the configuration above, the receive endpoint will create subscriptions for each event handled by the saga and those subscriptions will forward messages sent to the topic to the submit-order-queue. You don't need to create the subscription endpoints.