Auto Message Retry in RabbitMQ and Spring Boot

Auto Message Retry in RabbitMQ and Spring Boot


2 min read

In this article, you are going to learn how to auto-retry messages available on rabbitmq and Spring Boot applications. RabbitMQ is a queue messaging solution that will help you to have async communication between your services.


In the pub-sub implementation, a publisher should know whether the consumer consumed the message successfully or not which is the essential part. There are some patterns like a dead queue which is helping you to retry failed message.

Let us consider one scenario, you are using money transfer service but before money getting deducted from your account certain complaince and risk part needs to check that too handle in async way. Once complaince and risk factor satisfied then only send notification to deduct the money and transfer that to destination. In this scenario you need to make sure notification sent to perticular system and even in case of any failure happen the system should auto heal or auto retry.

Tech Stack:

  1. Java
  2. Spring Boot
  3. RabbitMQ
  4. Docker
  5. Gradle

RabbitMQ setup in local using Docker []

Let us create spring Boot application and make sure to have below dependencies.


      implementation 'org.springframework.boot:spring-boot-starter-amqp'
    implementation 'org.springframework.boot:spring-boot-starter-artemis'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.amqp:spring-rabbit-test'
// enable retry
// the first time will wait 5 seconds to try again
//try a maximum of 10 times
spring.rabbitmq.listener.simple.retry.multiplier=3.0 // multiplies the above range by 3

Let us write down the consumer to consume the message. Consumer / Listener:

public class QueueConsumer {

    @RabbitListener(queues = {"${}"})
    public void receive(@Payload String fileBody) throws BusinessException {
        System.out.println("Message Consumed " + fileBody +;

        if(Integer.parseInt(fileBody) == 1){
            throw new BusinessException("testing for exception");



SpringBootApplication class:

public class RabbitmqretryexampleApplication{

   public static void main(String[] args) {, args);


Now coding part is done, let us do validation send some proper message and send some improper message that should raise some exception and retry happen.


This article is about using property changes how you can achieve retry of messages in rabbitmq and spring boot.

Did you find this article valuable?

Support techwasti by becoming a sponsor. Any amount is appreciated!