1

I have planned to delay the processing of messages in queue by following these two links link1 link2. So, as suggested in the link. I have declared the original queue with the x-dead-letter-exchange and x-dead-letter-routing-key args. Which published the messages to the so called dead-letter-queue when message either failed to get processed by consumer or ttl happen or queue length exceed. Now in the dead-letter-queue similar args have been set along with the ttl parameter. Which is suppose to republish the messages to the original queue after ttl exceed. But the problem is it is dropping all the messages.

Moreover, there is a catch here. If i explicitly publish the failed messages from original queue to dead-letter-queue. Then after ttl it republish the messages to the original queue. Why is it so and how do i make it work. So that dead-letter-queue republishes the messages to the original queue instead of dropping. I am using RabbitMQ 3.0.0.

FYI, I have created both the exchanges of direct type along with the routing key

Naresh
  • 5,073
  • 12
  • 67
  • 124

2 Answers2

3

When a queue has a TTL setup that means that messages in that queue will be sent to the dead-letter-exchange (DLX) associated with that queue after the TTL has expired. If the queue has no DLX assigned then the messages go into the bit bucket.

If you want to send messages back into the queue from which they came to be re-processed then you need to have the setup that I described in this post.

Dead-lettering dead-lettered messages in RabbitMQ

Hopefully that is helpful for you.

Community
  • 1
  • 1
jhilden
  • 12,207
  • 5
  • 53
  • 76
  • Instead of doing what you suggested. We could also explicitly publish the failed message from original queue to dead-letter-queue instead of taking the help of `x-dead-letter-exchange` and `x-dead-letter-routing-key`. Then also dead-letter-queue republishes the messages to it's original queue after ttl. So, i am not able to understand what is the difference in publishing the message explicitly and via inbuilt functionality. – Naresh Apr 08 '16 at 16:57
  • the way you describe would only work if you had a single queue. In my link, that method works for having N number of queues that dead-letter into a single retry queue. – jhilden Apr 08 '16 at 17:02
  • Anyways, but why there is difference in publishing the message explicitly and via inbuilt functionality. Any ideas – Naresh Apr 08 '16 at 18:43
  • Could you please tell how do you maintain count of the failed messages. Do you use some inbuilt functionality or you had maintain custom variable of count and you increment everytime it is retried. – Naresh Apr 11 '16 at 09:49
  • @naresh, it's a customer variable that I increment. Here is my utility service for that: https://gist.github.com/jayhilden/2078872a53c7df0fe45d661861ed2d45 – jhilden Apr 11 '16 at 15:01
  • @Naresh did you figure it out? I'm having the same issue - some manuals tell that you can just re-queue with x-dead-letter-exchange back into original queue, but for me these messages just drop off after ttl. – Pavel Dubinin May 09 '17 at 12:08
  • @pavelDubinin, did you see my gist one comment above? – jhilden May 09 '17 at 15:25
  • @jhilden, yes - but I was hoping to have process automatic on rabbitmq level so that it goes [original queue] -> [dead letter queue] -> [original queue] via x-dead-letter-exchange setting on both queues but that seems not possible by design. – Pavel Dubinin May 10 '17 at 19:41
  • @jhilden do you manually publish the message to dead letter exchange ? – user269867 Mar 28 '18 at 22:20
  • @Naresh are you able to solve this? If yes, can you share some reference code? – user269867 Mar 28 '18 at 22:23
0

Suppose your original exchange is x.notification and is bind to the queue q.A with routing queue A. And your dead-letter-exchange namae is dlx.notification. Now in the queue q.A set ttl the time interval you want to wait and dead-lleter-exchange as dlx.notification. Now create another queue dlq.A to route the expired message from dlx.notification into dlq.A with routing key "A". I think thats all you need to do to achive your goal.

Manmay
  • 835
  • 7
  • 11