Does RabbitMQ capable in a way, I can define my consumer that it has a limit of consuming the same message. i.e my consumer doing a basic Reject with enqueue=true. And it will infinitely keep on listening to the same message. I am not talking about TTL on the queue side. But a control/config over consumer to tell I want to consume this only 5 times and then send it to another queue for instance. Can this be achieved ?
So yes I believe this can be done. You will need to cache the delivery tags of the messages received and also keep track of a reject count. Once the reject count for a particular message is great that five and then publish the message to another queue. You will also need to ACK back to RabbitMQ for the message recieved and likely create a new message (with a new delivery tag) and publish it.
This can be done on application level or via TTL and Dead Letter Exchanges. There is not known way to what you want on broker side (and I see no reason why you can't do that on consumer side)
P.S.: just make comment more visible
The main idea is to create custom ttl property (a-la hops count in TCP/IP packages) and decrease it every time message been consumed (and re-publish message body with new props). When it reaches zero - publish it to other queue.
来源:https://stackoverflow.com/questions/18261702/can-rabbitmq-consumer-configure-to-consume-only-a-defined-number-of-attempts-for