Skip to content

Synchronize all consumers of a queue to process only one message at a time

I am running a Spring Cloud Stream application, consuming messages from RabbitMq. I want to implement a behaviour where a given queue, having three consumers instances, delivers exactly one message to any of them, and wait for the next to be delivered until the current is acked (some sort of synchronization between all consumers).

I think that this can be done using this https://www.rabbitmq.com/consumer-prefetch.html with global option enabled, but I can’t find a way of achieving this using spring cloud stream. Any help will be appreciated.

Answer

Spring uses a separate channel for each consumer so global channel prefetch won’t have any effect.

Bear in mind that, even if it was supported, it would only work if the consumers were all in the same instance.