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?
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.
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.
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.
RabbitMQ has a plugin for consistent hash exchange. Using that exchange, and one consumer per queue, we can achieve message order with multiple consumers.
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With