Can I define retry mechanism for RabbitMQ message producer in SpringBoot?

Viewed 1054

I have the following RabbitMQ setup in the application.yml in my SpringBoot app which can consume (receive) messages:

spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: admin
    password: password
    listener:
      simple:
        retry:
          enabled: true
          initial-interval: 3s
          max-interval: 10s
          multiplier: 2
          max-attempts: 3

I want to create a different SpringBoot app where I can only send the messages.

My questions:

  1. is it possible to define retry setup for message-sending?
  2. if yes, is it the same as my example shows? since it is named listener: spring.rabbitmq.listener...

Thank you!

1 Answers

See the Boot Documentation about template.retry properties.

spring.rabbitmq.template.retry.enabled

false

Whether publishing retries are enabled.

spring.rabbitmq.template.retry.initial-interval

1000ms

Duration between the first and second attempt to deliver a message.

spring.rabbitmq.template.retry.max-attempts

3.0

Maximum number of attempts to deliver a message.

spring.rabbitmq.template.retry.max-interval

10000ms

Maximum duration between attempts.

spring.rabbitmq.template.retry.multiplier

1.0

Multiplier to apply to the previous retry interval.
Related