I'm trying to harmonize aspects of Spring AMQP with some stuff I read at the rabbitmq mailing list.
A few months ago, I read on the rabbit list a discussion about real and apparent concurrency when you specify multiple consumers, each reading from the same queue.
As I understand it, for a given channel, consumer callbacks are called serially. Apparently, this is done to preserve message ordering. However, if you create a distinct channel for each consumer, then the broker can drive the callbacks in parallel, there is no serialization requirement. The rabbit list discussion goes on to say:
Now, if you define a single Consumer instance, and get it to be invoked on multiple threads concurrently (on separate channels) you have to be careful -- the code in your Consumer must be thread-safe, and probably more than just that, too.
In light of these observations, can someone tell me what is going on when via Spring AMQP you set the number of concurrent consumers greater than one, e.g., you call:
against a SimpleMessageListenerContainer? I know that the consumers specified by numberConcurrentConsumers are, via the container's doStart() method, assigned to threads in the container's task executor. But:
- Does this constitute a "single consumer instance" as mentioned in the quote above? Or are there as many consumer instances as the value of the numberConcurrentConsumers argument?
- Does each of these threads establish its own channel (the parallel consumption case)?
- Or are they all sharing the same channel (the serialized consumption case)?