6
votes

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?

1

1 Answers

5
votes

(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.