问题
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