
Common mistake Creating only 1 waiting queue To achieve exponential backoff, you can simply increase the expiration time of the message on each retry. If you've configured everything properly, after 10 seconds, you'll see that the same message is now in the primary-queue. If you don't see any messages in the waiting-queue, refresh the page. Add any message in the "Payload" section.This means the message will stay in the waiting-queue for 10 seconds. In "Properties", add expiration and set its value to 10000 (10 seconds).Now expand the "Publish message" section and add the following details: Go to Queues tab and click on waiting-queue. That means, the message will stay in the waiting-queue only for 10 seconds and then it'll move to the primary-queue.

To know whether this routing is working properly, we'll publish a message to the waiting-queue with TTL of 10 seconds. Now expand Bindings and add the following details: Step 4: Set up Exchange Bindings for RoutingĪfter creating these 2 queues successfully, again go to Exchanges tab and click on the exchange that we created in step 2.
TORCHAT DELAYED MESSAGES WAITING TO BE SENT CODE
To keep this simple and straightforward, I don't want to code this in any particular language. Now, if we draw a diagram, it would look something like this ( Don't get overwhelmed by this diagram): If you don't want to send them immediately, you can skip the first 2 steps and directly insert the messages into the waiting queue. Keep increasing the TTL after each retry to achieve exponential backoff in case of failure.After that specific TTL, messages will be routed to the primary queue using the Exchange and can be consumed for trying again.If you don't get success, add the TTL and push it to the waiting queue.Try to send the notification to the clients immediately.Keep pushing the messages to the primary queue.For the particular webhooks use case, I decided to use this approach: It requires 2 queues (let's call them primary queue and waiting queue) and 1 exchange. To understand this approach, you must check out the links above to understand what are these two items. Using Dead Letter Exchange with Message TTL I found the Dead Letter Exchange with Message TTL approach significantly better than this plugin (Of course there are some limitations but at least this approach brings more consistency). That means if you set the message to be sent after a minute, an hour, or maybe a day and something happens to your servers, the messages are being consumed immediately once the server comes up. While writing this blog, it has one particular limitation that may bring inconsistencies to your application: If something happens to the RabbitMQ server or it restarts, your timers are lost. You can go to the plugin's Github repository and check the limitations. But you need to think twice before using this in the production environment. If you don't care too much about the timers you can go ahead with this very simple solution. If you want to jump to the implementation, you can read this article.

Let's look at the community plugin first.

