简体   繁体   中英

Is it possible to register multiple consumers for a RabbitMQ queue using MassTransit?

I use awesome MassTransit (v7.1.6) with .NET to publish and consume messages with RabbitMQ

To bind consumer to a specific queue I configure endpoints this way:

            configurator.ReceiveEndpoint(
                "QueueName",
                cfg =>
                {
                    cfg.ConfigureConsumer<MyConsumer>(context);
                    cfg.ExchangeType = Direct;
                });

So when I start my app I see only one consumer (and one connection for it) in the rabbit management UI, but to scale up the consuming and increase app productivity I want to increase the number of consumers and connections (one per consumer) for the queue

For example, in Apache RabbitMQ.Client we can call IModel.BasicConsume() multiple times for a channel

In MassTransit I see 'Concurrency Limit' and 'Concurrent Message Limit' but they don't affect the number of consumers on the Rabbit level so, as I see it, it's just an app-level scaling

Does MassTransit provide this feature?

You don't need to worry about the number of "consumers" that show up in RabbitMQ. MassTransit uses the PrefetchCount to have messages sent from RabbitMQ to the connected "RabbitMQ Consumer." The consumers in MassTransit are completely unrelated, and managed entirely by MassTransit. So you'll only see one "consumer" in RabbitMQ, but that only represents the connection/channel for the bus instance. Multiple concurrency messages are dispatched by MassTransit up to the PrefetchCount limit. As MassTransit consumers complete, new messages are pushed by RabbitMQ and dispatched by MassTransit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM