DEV Community

Cover image for implementing retry mechanism in rmq
Lakshan Dissanayake
Lakshan Dissanayake

Posted on

implementing retry mechanism in rmq

Rabbit MQ is an opensource message broker. We can publish messages to exchanges and queues can be bound to exchange with routing keys. Consumers will consume the payloads from the queues and so the application will work as intended.

Lets assume for some reason application couldn't process the payload and it rejects it, and we need to retry it with some delay? This is not rocket science, but lemme show you how I would have done it.

Image description

Pre-Conditions

  • q_work is bounded to ex_main with rk_work
  • DLX of q_work is ex_retry
  • DLX Routing Key of q_work is work
  • q_retry_work is bounded to ex_retry with rk_work
  • DLX of q_retry_work is ex_main
  • DLX Routing Key of q_retry_work is work
  • TTL of the q_retry_work is 30s

Producers publishes messages to ex_main.
Messages with rk_work routing key is immediately pushed to q_work.
The application will consume or reject messages.
Rejected messages are dropped to ex_retry and messages with rk_work will immediately pushed to q_retry_work.
Since no one is consuming from q_retry_work and after 30s it will dropped the messages to its DLX, which is ex_main.

Top comments (0)