Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

c# - How to set PrefetchCount when using ConnectReceiveEndpoint with MassTransit?

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;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

if (cfg is IRabbitMqReceiveEndpointConfigurator rabbit)
    rabbit.PrefetchCount = 80;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...