Consume only N messages from RabbitMQ with react\stomp, ack them separately and then exit

怎甘沉沦 提交于 2019-12-24 03:25:09

问题


I am using RabbitMQ with PHP react\stomp. I have two queues - one is "todo" other is "done". Consumer reads from "todo", do its work, ACKs the message, then publishes it to the "done" queue.

Is there any way of ensuring that I consume only N messages from "todo" (and ack them individually) and then quit? The main reason for that is we dont want to have long running consumers and we want to restart them after N messages.


回答1:


You can set a prefetch count for a destination:

The prefetch count for all subscriptions is set to unlimited by default. This can be controlled by setting the prefetch-count header on SUBSCRIBE frames to the desired integer count.

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

So to consume only ten messages, add the header

prefetch-count:10

to the SUBSCRIBE frame.

You can set the ack mode to client-individual for message-by-message manual acknowledgement.



来源:https://stackoverflow.com/questions/28672486/consume-only-n-messages-from-rabbitmq-with-react-stomp-ack-them-separately-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!