KoKo
KoKo

Reputation: 451

In-memory MassTransit scheduled message

I've used RabbitMQ Delayed Message Plugin for scheduling my message. it's worked without problem.

Now I want to configure in-memory MassTransit for scheduling messages at development environment.

My code in asp.net core:

Uri schedulerEndpoint = new Uri("queue:scheduler");
    services.AddMassTransit(x =>
    {
        x.AddMessageScheduler(schedulerEndpoint);

        x.AddConsumer<ScheduleNotificationConsumer>();

        x.UsingInMemory((context, cfg) => 
        {
            cfg.UseMessageScheduler(schedulerEndpoint);

            cfg.ConfigureEndpoints(context);
        });
    });

Well, this code doesn't call my consumer after the specific time.

I read this link and I guess I must use MassTransit.Quartz for in-memory scheduled messages, because , it said: the UseInMemoryScheduler method initializes Quartz.NET for standalone in-memory operation.

Is it correct? if yes, but this link used the follow code, that has dependency to RabbitMq:

services.AddMassTransit(x =>
        {
            x.AddMessageScheduler(new Uri("queue:scheduler"));

            x.UsingRabbitMq((context, cfg) => 
            {
                cfg.UseInMemoryScheduler("scheduler");

                cfg.ConfigureEndpoints(context);
            });
        });

but I don't want to have any dependency to RabbitMq in development environment.

Upvotes: 0

Views: 2913

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33542

If you're using the in-memory transport, you can use the new delayed scheduling that was included in 7.1.8. This standardizes the configuration across all transports, and for the first time provides in-memory scheduling without Quartz.NET.

To configure the new delayed scheduler, use:

services.AddMassTransit(x =>
{
    x.AddDelayedMessageScheduler();

    x.UsingInMemory((context, cfg) => 
    {
        cfg.UseDelayedMessageScheduler();

        cfg.ConfigureEndpoints(context);
    });
});

Upvotes: 1

Related Questions