Consume only N messages from RabbitMQ using the \ stomp reaction, run them separately, and then exit

I am using RabbitMQ with php response \ stomp. I have two lines: one is todo, the other is done. The consumer reads "todo", does its job, passes the ACK message, and then publishes it to the "done" queue.

Is there a way to ensure that I only consume N messages from "todo" (and separately), and then leave? The main reason for this is that we do not want users to work for a long time, and we want to restart them after N messages.

+1
source share
1 answer

You can set a prefetch counter for the recipient:

The prefetch account for all signatures is set to unlimited by default. This can be controlled by setting the prefetch counter header on SUBSCRIBE frames to the desired integer value.

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

To consume only ten messages, add a header

prefetch-count:10 

to the SUBSCRIBE frame.

You can set ack mode to client-individual to confirm for each message.

+1
source

All Articles