[rabbitmq-discuss] Message is delivered to all queue consumers when rabbitmq crashes

Simon MacMullen simon at rabbitmq.com
Fri Oct 21 12:37:48 BST 2011


On 19/10/11 21:02, rasadoll wrote:
> I have multiple queue consumers running at the same time. They all
> listen to one single queue. Messages are sent to the default exchange
> with queue name as the routing key. When one of the consumers is busy
> processing a message, before acking the message if RabbitMQ service
> crashes (simply by stopping the service), the message is sent to all
> other consumers immediately which results in processing the same
> message multiple times concurrently. Is this the right behavior for
> RabbitMQ?

No. RabbitMQ should really only deliver a given message from a queue to 
a single consumer.

I haven't been able to replicate the behaviour you describe.

Cheers, Simon

> Here is my queue design:
>
> Map<String, Object>  args = new HashMap<String, Object>();
> args.put("x-ha-policy", "all");
> channel.queueDeclare(JOB_EXEC_QUEUE, true, false, false, args);
>
> I use durable HA queue but I am not running in a clustered
> environment.
> ===========================
> Message publishing:
>
> channel.basicPublish("", JOB_EXEC_QUEUE,
> MessageProperties.PERSISTENT_BASIC, message.getBytes());
> ===========================
> Consumer Code:
>
> channel.basicQos(1);
> QueueingConsumer consumer = new QueueingConsumer(channel);
> channel.basicConsume(JOB_EXEC_QUEUE, consumer);
>
> QueueingConsumer.Delivery delivery;
> while (true) {
>          try {
>            delivery = consumer.nextDelivery();
>          } catch (InterruptedException ie) {
>            continue;
>          }
>
> // process the message
>
>         channel.basicAck(delivery.getEnvelope().getDeliveryTag(),
> false);
> }
>
> I stop the service when one consumer is in the process message phase.
>
> Am I doing something wrong? Is this an expected behavior for RabbitMQ?
>
> Thanks,
> Reza
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


-- 
Simon MacMullen
RabbitMQ, VMware


More information about the rabbitmq-discuss mailing list