Overview
Message by prefetching is consumer prefetch mechanism extended.
AMQP 0-9-1
Specifies the basic.qos
method in such a Channel (one connection) is not able to limit the number of notification messages when the consumer. Unfortunately, not Channel preferable range - can be consumed as a single channel from a plurality of queues, queue channels, and the need to coordinate to ensure that each message sent will not exceed this limit to each other. On a single machine that will slow, while consumption from a cluster will be very slow.
In addition, for many cases, specify applicable to each consumer pre-fetch count more natural.
Therefore, RabbitMQ redefines the basic.qos
method of global
the significance of the sign:
global | Meaning of prefetch_count in AMQP 0-9-1 |
Meaning of prefetch_count in RabbitMQ |
---|---|---|
false | All consumers on a shared channel | They were applied to each new consumers on the channel |
true | All consumers in connection sharing | All consumers on a shared channel |
In most of the API's global
default flag is false.
Individual consumers
The following example Java substantially up to the last received message unacknowledged 10:
Channel channel = ...;
Consumer consumer = ...;
channel.basicQos(10); // Per consumer limit
channel.basicConsume("my-queue", false, consumer);
Independent consumer
In this example, a channel with two consumer-enabled, each set to receive a maximum 10 unacknowledged messages at the same time as an independent:
Channel channel = ...;
Consumer consumer1 = ...;
Consumer consumer2 = ...;
channel.basicQos(10); // Per consumer limit
channel.basicConsume("my-queue1", false, consumer1);
channel.basicConsume("my-queue2", false, consumer2);
More consumers sharing limit
AMQP 0-9-1
Explanation does not explain with different global
signs called many times basic.qos
what happens. RabbitMQ explain both prefetch limits will mutually independent execution; consumers acquired message in a case where two limits are not reached.
Example:
Channel channel = ...;
Consumer consumer1 = ...;
Consumer consumer2 = ...;
channel.basicQos(10, false); // Per consumer limit
channel.basicQos(15, true); // Per channel limit
channel.basicConsume("my-queue1", false, consumer1);
channel.basicConsume("my-queue2", false, consumer2);
There are unconfirmed news of 15 between the two consumers, each consumer has a maximum of 10 messages. It will be smaller than the previous example are slow, because the channels and queues are performing global restrictions, generate additional costs resulting from the coordination.
Translated from:
1. https://www.rabbitmq.com/consumer-prefetch.html