What is the behavior when using the following construct (latest version of Spring). I'm unable to find it in the documentation.
@RabbitListener(queues = {"q1", "q2", "q3"})
public class MyListener {
In which order are the messages from the 3 queues processed?
It is indeterminate - 3 basicConsume
operations are performed on the consumer channel (if you increase concurrentConsumers it's 3 per consumer). The basicConsume
operations are normally performed in the order the queues are defined (in all cases unless one or more of the queues is temporarily "missing").
The broker will send messages from each queue up to the prefetchCount
(basicQos
) for each queue (default 1).
I don't know the actual algorithm used by the broker in this scenario but you should assume it to be indeterminate - Spring AMQP will deliver them to the listener(s) in the order received from the broker.
EDIT
I just ran a test (2 queues each with 2 existing messages) and they were delivered round-robin - q1m1, q2m1, q1m2, q2m2 when the prefetch was 1.
With prefetch set to 4, I see q1m1, q1m2, q2m1, q2m2.
Of course, when the queues are empty, messages will generally arrive in the order they arrive at the broker.
EDIT2
See Consumer Prefetch.
Spring AMQP uses the basicQos
variant with no global arg, so the default (false
) is used. That means the prefetch is per-consumer.