0

I am trying to use scheduler in MassTransit state machine saga without specifying the scheduler service address directly.

I use UseMessageScheduler in the bus configuration and it works fine since I can do context.Schedule from inside my consumers.

However, it does not work in sagas. When I try to do .Schedule, I get this error:

A request timeout was specified but no message scheduler was specified or available

I checked the MT code and I see this:

MessageSchedulerContext schedulerContext;
if (_request.Settings.SchedulingServiceAddress != null)
{
    ISendEndpoint scheduleEndpoint = await consumeContext.GetSendEndpoint(_request.Settings.SchedulingServiceAddress).ConfigureAwait(false);

    await scheduleEndpoint.ScheduleSend(consumeContext.ReceiveContext.InputAddress, expirationTime, message).ConfigureAwait(false);
}
else if (consumeContext.TryGetPayload(out schedulerContext))
    await schedulerContext.ScheduleSend(message, expirationTime, Pipe.Empty<SendContext>()).ConfigureAwait(false);
else
    throw new ConfigurationException("A request timeout was specified but no message scheduler was specified or available");

So, there is actually a branch that should normally get the scheduler address from the configuration, but why doesn't it work?

Alexey Zimarev
  • 17,944
  • 2
  • 55
  • 83

1 Answers1

0

So, to make sure that you're configuring the scheduler correctly, the call to UseMessageScheduler should be placed on the main bus configurator so that all endpoints have access to it. If the scheduler endpoint is configured within the same bus instance, it should look something like:

configurator.ReceiveEndpoint("quartz", e =>
{
    configurator.UseMessageScheduler(e.InputAddress);

    e.Consumer(() => new ScheduleMessageConsumer(scheduler));
    e.Consumer(() => new CancelScheduledMessageConsumer(scheduler));
});

Notice that the endpoint address is pulled from the receive endpoint, and that the scheduler is configured on the main bus configurator. If the scheduler address is from configuration, the URI should be specified as the address.

Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
  • This is exactly what I have in my code and I got an error that scheduling service address is not specified. May be I have some silly mistake, will double check. – Alexey Zimarev Apr 22 '16 at 19:03