I am using Spring AMQP to work with RabbitMQ. Here is my configuration:
<rabbit:connection-factory id="connectionFactory"
host="${queue.host}" port="${queue.port}" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" />
<rabbit:admin connection-factory="connectionFactory" />
<rabbit:queue name="${queue.names}" durable="true"
exclusive="false" />
<rabbit:listener-container
connection-factory="connectionFactory" acknowledge="auto" error-handler="airbrakeHandler" prefetch="1000" >
<rabbit:listener ref="consumer" queue-names="${queue.names}" />
</rabbit:listener-container>
As you can see the prefetchCount is 1000.
I was wondering whether the the prefetched messages are processed in parallel in the consumer; that is, multiple threads calling the onMessage(Message message) method. Or are the messages rather processed sequentially; that is, one thread that iterates over the prefetched messages and calls on each message the onMessage(Message message) method in a sequntial manner.
I should note that the order of the processing is not important for me. Just the fact that they are processed one at a time.
Thanks in advance.
The SimpleMessageListenerContainer
configuration includes a concurrency
parameter to set the maximum number of consumer threads:
concurrency: The number of concurrent consumers to start for each listener.
For single-threaded operation, you'd set this to "1" - for example:
<rabbit:listener-container ... prefetch="1000" concurrency="1">
<rabbit:listener ref="consumer" queue-names="${queue.names}" />
</rabbit:listener-container>
More information in the Spring Docs and the javadoc for SimpleMessageListenerContainer
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With