diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java index 25263248c2a..88c0be73cc8 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java @@ -107,7 +107,7 @@ public class RabbitAutoConfiguration { } Template template = config.getTemplate(); Retry retry = template.getRetry(); - if (retry.isEnable()) { + if (retry.isEnabled()) { RetryTemplate retryTemplate = new RetryTemplate(); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(retry.getMaxAttempts()); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index 938e504c9d0..1009cec1059 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -22,6 +22,7 @@ import java.util.Set; import org.springframework.amqp.core.AcknowledgeMode; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.util.StringUtils; /** @@ -396,6 +397,7 @@ public class RabbitProperties { /** * Optional properties for a retry interceptor. */ + @NestedConfigurationProperty private final ListenerRetry retry = new ListenerRetry(); public boolean isAutoStartup() { @@ -462,6 +464,7 @@ public class RabbitProperties { public static class Template { + @NestedConfigurationProperty private final Retry retry = new Retry(); /** @@ -501,16 +504,16 @@ public class RabbitProperties { /** * Whether or not publishing retries are enabled. */ - private boolean enable; + private boolean enabled; /** - * The maximum number of attempts to publish or deliver a message. + * Maximum number of attempts to publish or deliver a message. */ private int maxAttempts = 3; /** - * The interval between the first and second attempt to publish - * or deliver a message. + * Interval between the first and second attempt to publish or deliver + * a message. */ private long initialInterval = 1000L; @@ -520,16 +523,16 @@ public class RabbitProperties { private double multiplier = 1.0; /** - * The maximum interval between attempts. + * Maximum interval between attempts. */ private long maxInterval = 10000L; - public boolean isEnable() { - return this.enable; + public boolean isEnabled() { + return this.enabled; } - public void setEnable(boolean enable) { - this.enable = enable; + public void setEnabled(boolean enabled) { + this.enabled = enabled; } public int getMaxAttempts() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java index 0d4d42a0f2a..55521dbd145 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java @@ -91,14 +91,9 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer { factory.setDefaultRequeueRejected(listenerConfig.getDefaultRequeueRejected()); } ListenerRetry retryConfig = listenerConfig.getRetry(); - if (retryConfig.isEnable()) { - RetryInterceptorBuilder builder; - if (retryConfig.isStateless()) { - builder = RetryInterceptorBuilder.stateless(); - } - else { - builder = RetryInterceptorBuilder.stateful(); - } + if (retryConfig.isEnabled()) { + RetryInterceptorBuilder builder = (retryConfig.isStateless() ? + RetryInterceptorBuilder.stateless() : RetryInterceptorBuilder.stateful()); factory.setAdviceChain(builder .maxAttempts(retryConfig.getMaxAttempts()) .backOffOptions(retryConfig.getInitialInterval(), @@ -106,6 +101,7 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer { .recoverer(new RejectAndDontRequeueRecoverer()) .build()); } + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java index cc06314cf3d..987cc798765 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java @@ -147,11 +147,11 @@ public class RabbitAutoConfigurationTests { @Test public void testRabbitTemplateRetry() { - load(TestConfiguration.class, "spring.rabbitmq.template.retry.enable:true", - "spring.rabbitmq.template.retry.max-attempts:4", - "spring.rabbitmq.template.retry.initial-interval:2000", + load(TestConfiguration.class, "spring.rabbitmq.template.retry.enabled:true", + "spring.rabbitmq.template.retry.maxAttempts:4", + "spring.rabbitmq.template.retry.initialInterval:2000", "spring.rabbitmq.template.retry.multiplier:1.5", - "spring.rabbitmq.template.retry.max-interval:5000", + "spring.rabbitmq.template.retry.maxInterval:5000", "spring.rabbitmq.template.receiveTimeout:123", "spring.rabbitmq.template.replyTimeout:456"); RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class); @@ -248,17 +248,17 @@ public class RabbitAutoConfigurationTests { @Test public void testRabbitListenerContainerFactoryWithCustomSettings() { load(MessageConvertersConfiguration.class, - "spring.rabbitmq.listener.retry.enable:true", - "spring.rabbitmq.listener.retry.max-attempts:4", - "spring.rabbitmq.listener.retry.initial-interval:2000", + "spring.rabbitmq.listener.retry.enabled:true", + "spring.rabbitmq.listener.retry.maxAttempts:4", + "spring.rabbitmq.listener.retry.initialInterval:2000", "spring.rabbitmq.listener.retry.multiplier:1.5", - "spring.rabbitmq.listener.retry.max-interval:5000", + "spring.rabbitmq.listener.retry.maxInterval:5000", "spring.rabbitmq.listener.autoStartup:false", "spring.rabbitmq.listener.acknowledgeMode:manual", "spring.rabbitmq.listener.concurrency:5", "spring.rabbitmq.listener.maxConcurrency:10", "spring.rabbitmq.listener.prefetch:40", - "spring.rabbitmq.listener.default-requeue-rejected:false", + "spring.rabbitmq.listener.defaultRequeueRejected:false", "spring.rabbitmq.listener.transactionSize:20"); SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context .getBean("rabbitListenerContainerFactory", diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index e5ce4e90620..f6148a882a8 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -771,10 +771,10 @@ content into your application; rather pick only the properties that you need. spring.rabbitmq.listener.default-requeue-rejected= # Whether or not to requeue delivery failures; default `true`. spring.rabbitmq.listener.max-concurrency= # Maximum number of consumers. spring.rabbitmq.listener.prefetch= # Number of messages to be handled in a single request. It should be greater than or equal to the transaction size (if used). - spring.rabbitmq.listener.retry.enable= # Set to true to enable stateless retries for listener containers. - spring.rabbitmq.listener.retry.initial-interval=1000 # The interval between the first and second attempt to deliver a message. - spring.rabbitmq.listener.retry.max-attempts=3 # The maximum number of attempts to deliver a message. - spring.rabbitmq.listener.retry.max-interval=10000 # The maximum number of attempts to deliver a message. + spring.rabbitmq.listener.retry.enabled= # Whether or not publishing retries are enabled. + spring.rabbitmq.listener.retry.initial-interval=1000 # Interval between the first and second attempt to deliver a message. + spring.rabbitmq.listener.retry.max-attempts=3 # Maximum number of attempts to deliver a message. + spring.rabbitmq.listener.retry.max-interval=10000 # Maximum number of attempts to deliver a message. spring.rabbitmq.listener.retry.multiplier=1.0 # A multiplier to apply to the previous delivery retry interval. spring.rabbitmq.listener.retry.stateless=true # Whether or not retry is stateless or stateful. spring.rabbitmq.listener.transaction-size= # Number of messages to be processed in a transaction. For best results it should be less than or equal to the prefetch count. @@ -786,12 +786,12 @@ content into your application; rather pick only the properties that you need. spring.rabbitmq.ssl.key-store-password= # Password used to access the key store. spring.rabbitmq.ssl.trust-store= # Trust store that holds SSL certificates. spring.rabbitmq.ssl.trust-store-password= # Password used to access the trust store. - spring.rabbitmq.template.receiveTimeout=0 # Timeout for `receive()` methods. - spring.rabbitmq.template.replyTimeout=5000 # Timeout for `sendAndReceive()` methods. - spring.rabbitmq.template.retry.enable= # Set to true to enable retries in the `RabbitTemplate`. - spring.rabbitmq.template.retry.initial-interval=1000 # The interval between the first and second attempt to publish a message. - spring.rabbitmq.template.retry.max-attempts=3 # The maximum number of attempts to publish a message. - spring.rabbitmq.template.retry.max-interval=10000 # The maximum number of attempts to publish a message. + spring.rabbitmq.template.receive-timeout=0 # Timeout for `receive()` methods. + spring.rabbitmq.template.reply-timeout=5000 # Timeout for `sendAndReceive()` methods. + spring.rabbitmq.template.retry.enabled= # Set to true to enable retries in the `RabbitTemplate`. + spring.rabbitmq.template.retry.initial-interval=1000 # Interval between the first and second attempt to publish a message. + spring.rabbitmq.template.retry.max-attempts=3 # Maximum number of attempts to publish a message. + spring.rabbitmq.template.retry.max-interval=10000 # Maximum number of attempts to publish a message. spring.rabbitmq.template.retry.multiplier=1.0 # A multiplier to apply to the previous publishing retry interval. spring.rabbitmq.username= # Login user to authenticate to the broker. spring.rabbitmq.virtual-host= # Virtual host to use when connecting to the broker. diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index e09d8ab22d4..de2bd7a87cf 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -3801,9 +3801,8 @@ automatically to the auto-configured `AmqpTemplate`. Any `org.springframework.amqp.core.Queue` that is defined as a bean will be automatically used to declare a corresponding queue on the RabbitMQ instance if necessary. -You can enable retries on the `AmqpTemplate` to retry operations, for example in the event the broker connection is -lost. -Retries are disabled by default. +You can enable retries on the `AmqpTemplate` to retry operations, for example in the event +the broker connection is lost. Retries are disabled by default. [[boot-features-using-amqp-receiving]] ==== Receiving a message