Can RabbitMQ consumer configure to consume only a defined number of attempts for the same message

╄→尐↘猪︶ㄣ 提交于 2019-12-20 04:25:18

问题


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 ?


回答1:


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.




回答2:


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

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