Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way for RabbitMQ STOMP to stop consuming messages until previous will ACKed?

Tags:

rabbitmq

stomp

I use RabbitMQ Web-STOMP in my project and it is very good for me, but there is one problem with it. When consumer subscribes to a queue it gets instantly all the messages from the queue. In my case, a message task may take much time and it is necessary to consumer get next message from a queue only when previous was completed.

All works fine, when publishing starts after the consumers are subscribed, but when there are already messages in a queue, first subscribed consumer will get all of them and others will stay free. Is there anything like node-amqp queue.shift() method to consume next message only when previous is ACKed?

like image 295
Le chat du rabbin Avatar asked Nov 29 '12 10:11

Le chat du rabbin


People also ask

Does RabbitMQ delete message after consumed?

you are telling RabbitMQ to automatically acknowledge the message when it is consumed. acknowledging a message tells RabbitMQ that it has been taken care of and RabbitMQ can delete it now.

Does RabbitMQ retain messages?

Persistent messages will be written to disk as soon as they reach the queue, while transient messages will be written to disk only so that they can be evicted from memory while under memory pressure. Persistent messages are also kept in memory when possible and only evicted from memory under memory pressure.

What happens to unacknowledged messages in RabbitMQ?

RabbitMQ Unacked Messages are the messages that are not Acknowledged. If a consumer fails to acknowledge messages, the RabbitMQ will keep sending new messages until the prefetch value set for the associated channel is equal to the number of RabbitMQ Unacked Messages count.

Can two consumers consume the same message RabbitMQ?

RabbitMQ has a plugin for consistent hash exchange. Using that exchange, and one consumer per queue, we can achieve message order with multiple consumers.


1 Answers

(Which client are you using?)

The answer to your question is basic_qos, see amqp reference and search for basic.qos

In the c# API you would do the following:

int prefetch = 10;

IModel channel = connection.CreateModel(); //where connection is IConnection
channel.basic_qos(0, prefetch, false);

The prefetch size can be used to tell the rabbitmq server how many messages to send down to the consumer until they are ACK'd. The prefetch size is ignored if the NO-ACK option is set.

Bear in mind setting this value can have a potential performance impact, take a look at this.

like image 115
kzhen Avatar answered Oct 27 '22 21:10

kzhen