Search code examples
masstransit

Why when using Request in Saga when using Mediator I get exception that scheduler was not found?


I am using MassTransit 8.1.3 and Mediator transport as follows:

services.AddMediator(x => {
   x.AddSagaStateMachine<MyStateMachine, MyState>().InMemoryRepository();
});

In my saga I am doing request:

/*
At first declare request in state machine like this:
public Request<
        MyState, 
        GetSomething, 
        GetSomethingResponse> 
        GetSomethingRequst { get; private set; } = null!;
*/

Request(() => GetSomethingRequest);

Initially(When(MyEvent)
    .Then(context =>
    {
        // ...
    })
    .Request(GetSomethingRequest, context => new GetSomething {})
    .TransitionTo(MyOtherState));

The problem is that when MyEvent is received by Saga I get following exception:

---> MassTransit.ConfigurationException: A request timeout was specified but no message scheduler was specified or available
         at MassTransit.SagaStateMachine.RequestActivityImpl`3.SendRequest(BehaviorContext`1 context, SendTuple`1 sendTuple, Uri serviceAddress) in /_/src/MassTransit/SagaStateMachine/SagaStateMachine/Activities/RequestActivityImpl.cs:line 45
         at MassTransit.SagaStateMachine.RequestActivity`4.Execute(BehaviorContext`2 context, IBehavior`2 next) in /_/src/MassTransit/SagaStateMachine/SagaStateMachine/Activities/RequestActivity.cs:line 110
         at MassTransit.SagaStateMachine.ActivityBehavior`1.Execute[T](BehaviorContext`2 context) in /_/src/MassTransit/SagaStateMachine/SagaStateMachine/Behaviors/ActivityBehavior.cs:line 53

To me it seems like a bug - I couldnt find a way to register any scheduler for Mediator transport. I tried to add MassTransit.Quartz but it does not fix the issue (I tried to call .AddQuartz() both on ServiceCollection as well as on IMediatorRegistrationConfigurator). Or maybe I am missing something?


Solution

  • It isn't a bug, you're using mediator for things which it should never be used.

    Scheduling, sagas with requests, basically anything that isn't immediately executed is a no-go when using mediator.