MWKZ
MWKZ

Reputation: 124

Connecting two services to same VHost using MassTransit 7 to process jobs (JobSlotUnavailable)

I am moving from Hangfire to MassTransit 7/RabbitMQ in order to execute backend jobs. We have many windows services where each service processes a group of jobs.

When I start service A alone, jobs consumers are executed normally and I can see that each Job is executed where the audit store is receiving JobSlotAllocated event.

If I start service B alone, Jobs are executed normally as well.

Now if both services are started, MassTransit stops from releasing the slots and only the first 20 jobs are executed (Concurrent limit is set to 20), and the audit store starts receiving JobSlotUnavailable event.

Is there any configuration needs to be done in order to allow both services to consume jobs?

Bus configuration is as follows:

        services.AddMassTransit(busConfigurator =>
        {
            busConfigurator.SetKebabCaseEndpointNameFormatter();

    //Register commands, jobs, ...

            busConfigurator.AddRabbitMqMessageScheduler();

            busConfigurator.UsingRabbitMq((context, cfg) =>
            {



                cfg.Host(busOptions.Host, "/", h =>
                {
                    h.Username(busOptions.Username);
                    h.Password(busOptions?.Password);
                });


                cfg.UseDelayedExchangeMessageScheduler();

                

                if (serviceInstance)
                {
                    var options = new ServiceInstanceOptions();
                    options.EnableInstanceEndpoint();
                    options.EnableJobServiceEndpoints();

                    cfg.ServiceInstance(options, instance =>
                    {
                        instance.ConfigureJobService();

                        instance.ConfigureJobServiceEndpoints(a =>
                        {
                            a.StartJobTimeout = TimeSpan.FromSeconds(30);
                        });

                        instance.ConfigureEndpoints(context);
                    });
                }
                else
                {
                    cfg.ConfigureEndpoints(context);
                }
            });
        });

        services.AddMassTransitHostedService();

Thank You,

Upvotes: 0

Views: 401

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33268

You need to configure a shared saga repository for the job service. What you have currently is using in-memory, which is per instance, and won't work.

You can see how to configure EF Core as a saga repository for the job service in this sample.

Upvotes: 1

Related Questions