0

As default, MassTransit sets the PrefetchCount to 16. I would like to change that. I can do this when configuring MassTransit. But when using ConnectReceiveEndpoint I cannot set the PrefetchCount. If I set the PrefetchCount doing configuration, then MassTransit will create some random queues which correctly has a PrefetchCount that I defined, but the queues created with ConnectReceiveEndpoint still have the default value of 16.

Is there any way to set the PrefetchCount for queues created with ConnectReceiveEndpoint?

    public async Task SubscribeAsync<T>(Func<T, Task> callback, string queueName) where T : class, IMessage
    {
        queueName ??= $"{Assembly.GetEntryAssembly().GetName().Name}_{Environment.MachineName}";

        hostHandler = busControl.ConnectReceiveEndpoint(queueName, cfg =>
        {
            cfg.Handler<T>(async context =>
            {
                return callback(context.Message);
            },
            config =>
            {
                config.UseConcurrentMessageLimit(10);
                config.UseMessageRetry(r => r.Exponential(3, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(2)));
            });
        });

        await hostHandler.Ready;
    }
Michael
  • 3,350
  • 2
  • 21
  • 35

1 Answers1

1

You can check the type of the configurator, and use it appropriately:

if (cfg is IRabbitMqReceiveEndpointConfigurator rabbit)
    rabbit.PrefetchCount = 80;
Chris Patterson
  • 28,659
  • 3
  • 47
  • 59
  • Yeah, I ended up doing the same thing. Any reason PrefetchCount is not move to a higher abstraction level? – Michael Jan 13 '21 at 20:24
  • Well, it could, but it isn't exactly the same on each transport. I have other ideas I'm toying around with to make these types of settings more ubiquitous but nothing to release yet. – Chris Patterson Jan 14 '21 at 04:39