[rabbitmq-discuss] parallel consuming from one queue

Emile Joubert emile at rabbitmq.com
Thu Mar 24 16:50:37 GMT 2011


Hi Jan,

On 24/03/11 16:38, Jan Andersson wrote:
> Hi,
>
> Hi,
> we are trying to setup something that we hoped would be pretty straight
> forward but can't seem to get it to work.
> We want to consume messages from a persistent queue and use ack:s.
> However all of our attempts end in us consuming one message off the
> queue and then no one else (thread or process) can consume messages off
> the queue until that message has been ack:ed.
>
> This is in Java, we set up one channel per thread like this:
> [code]
> channel = connection.createChannel();
> channel.exchangeDeclare(configuration.getExchangeName(), "topic", true);
> channel.queueDeclare(queueName, true); // durable queue
> channel.queueBind(queueName, configuration.getExchangeName(), routingKey);
> consumer = new QueueingConsumer(channel);

channel.basicQos(SMALL_NUMBER);

> channel.basicConsume(queueName, false, consumer);
> [/code]
>
> The ack is done like this:
> [code]
> channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);
> [/code]
>
> Might be hard to answer this but if anyone could point us in the right
> direction that would be great!

You should set QoS on each channel. The first QueueingConsumer has taken 
all the messages - that's why no other consumers can retrieve messages. 
Setting QoS will prevent the broker from delivering more than the set 
number of messages without acknowledgement and allow other consumers to 
retrieve some messages.

Regards

Emile


More information about the rabbitmq-discuss mailing list