1

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 ?

Subash Chaturanga
  • 814
  • 2
  • 10
  • 20

2 Answers2

1

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.

pinepain
  • 12,453
  • 3
  • 60
  • 65
  • TTL will say messages in this queue should leave the queue after X amount of time. This is not exactly what I want. What I want is from consumer side, to configure it to consume the same message a given number of time and then send it to a different queue. Can this be done from consumer end ? would you mind give a small example on how to? – Subash Chaturanga Aug 16 '13 at 13:04
  • i don't know the exact java syntax how to do that, but 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. When it reaches zero - publish it to other queue. – pinepain Aug 16 '13 at 13:21
  • Hi zaq178miami, do you know API calls to set/get the TTL from cunsumer? – Subash Chaturanga Aug 19 '13 at 15:55
  • Message properties can be changed (normally) only on publish. After that if you want to change props or body you have to re-publish message with new data. In you task, I guess, the only important part is message body. So you can consume message, and then publish new one with the same body and different params. More on this link https://www.rabbitmq.com/ttl.html – pinepain Aug 19 '13 at 18:46
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.

Ian Dallas
  • 12,451
  • 19
  • 58
  • 82
  • Hi tkeE2036, Is there a way to keep track on reject count from broker side in rabbitMQ ? Or do I need to manually persist the status to a DB and keep track on rejected count from there. – Subash Chaturanga Aug 20 '13 at 17:15