[rabbitmq-discuss] parallel consuming from one queue

Jan Andersson Jan.Andersson at UNIBET.com
Fri Mar 25 10:16:54 GMT 2011


On 03/25/2011 09:10 AM, Jan Andersson wrote:
> On 03/24/2011 05:50 PM, Emile Joubert wrote:
>> 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
>
> Hi,
> after setting the QoS like "channel.basicQos(1);" we can pickup messages
> in parallel.
> However, every message gets the deliveryTag set to 1. So when we ack the
> 2nd, 3rd... message we get the error:
>
> channel error; reason:
> {#method<channel.close>(reply-code=406,reply-text=PRECONDITION_FAILED -
> unknown delivery tag 1,class-id=60,method-id=80),null,""}
>
> Are we consuming the messages in the wrong way somehow?
> (QueueingConsumer.Delivery delivery = consumer.nextDelivery();)
>
> thanks for your quick reply,
> regards
> Jan
>
This was our own fault, we reused the same channel by mistake.
sorry for the bother,
Janne
The information in this email is confidential and may be legally privileged.
If you are not the intended recipient, you must not read, use or disseminate that information
and upon reception, permanently delete the original and destroy any copies.
Although this email and any attachments are believed to be free of any virus
or any other defect which might affect any computer or IT system into which
they are received and opened, it is the responsibility of the recipient to
ensure that they are virus free and no responsibility is accepted by Unibet
for any loss or damage arising in any way from receipt or use thereof.



More information about the rabbitmq-discuss mailing list