Mani
Mani

Reputation: 1374

What happens to message in queue of 1 length which is not acked in rabbitmq?

So I have declared a queue of length 1 and the publisher is made not to auto - ack the messages which means that I have ack each and every message I receive.So what happens here with the message that is not acked ?

When the new message is arrived on the queue, what happens to the old unacked message ?

Map < String, Object > args = new HashMap < String, Object > ();
args.put("x-max-length", 1);
channel.queueDeclare("myqueue", false, false, false, args);
channel.basicConsume("myqueue", false, consumer);

What I want to achieve is myqueue should hold only one message and any publisher can read the message but it shouldn't delete the message. When a new message arrives on the queue it should erase that message and put the new message.

Upvotes: 2

Views: 444

Answers (1)

old_sound
old_sound

Reputation: 2313

RabbitMQ cannot delete messages that are already delivered to the consumers. If the consumer decided to ack the messages, then RabbitMQ will wait for for either an ack/nack or reject from the consumer in order to decide what to do with said message.

Messages that are delivered to consumers are not counted towards the queue length.

From the docs:

In all cases the number of ready messages is used; unacknowledged messages do not count towards the limit.

https://www.rabbitmq.com/maxlength.html

Imagine you are on a queue at the airport, and then its your turn to check-in, you are not on the queue anymore, if someone is asked to count the queue length, that person won't take you into account. RabbitMQ does something similar with queue length.

Upvotes: 2

Related Questions