diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/AbstractRabbitListenerContainerFactoryConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/AbstractRabbitListenerContainerFactoryConfigurer.java index 578a8245972..d271bc0fea4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/AbstractRabbitListenerContainerFactoryConfigurer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/AbstractRabbitListenerContainerFactoryConfigurer.java @@ -116,9 +116,7 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer builder = (retryConfig.isStateless()) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index dcbf0f318e9..b8bc40ec19a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -592,12 +592,6 @@ public class RabbitProperties { */ private Duration idleEventInterval; - /** - * Whether to fail if the queues declared by the container are not available on - * the broker. - */ - private Boolean missingQueuesFatal; - /** * Optional properties for a retry interceptor. */ @@ -643,13 +637,7 @@ public class RabbitProperties { this.idleEventInterval = idleEventInterval; } - public Boolean getMissingQueuesFatal() { - return this.missingQueuesFatal; - } - - public void setMissingQueuesFatal(Boolean missingQueuesFatal) { - this.missingQueuesFatal = missingQueuesFatal; - } + public abstract boolean isMissingQueuesFatal(); public ListenerRetry getRetry() { return this.retry; @@ -679,6 +667,13 @@ public class RabbitProperties { */ private Integer transactionSize; + /** + * Whether to fail if the queues declared by the container are not available on + * the broker and/or whether to stop the container if one or more queues are + * deleted at runtime. + */ + private boolean missingQueuesFatal = true; + public Integer getConcurrency() { return this.concurrency; } @@ -703,6 +698,15 @@ public class RabbitProperties { this.transactionSize = transactionSize; } + @Override + public boolean isMissingQueuesFatal() { + return this.missingQueuesFatal; + } + + public void setMissingQueuesFatal(boolean missingQueuesFatal) { + this.missingQueuesFatal = missingQueuesFatal; + } + } /** @@ -715,6 +719,12 @@ public class RabbitProperties { */ private Integer consumersPerQueue; + /** + * Whether to fail if the queues declared by the container are not available on + * the broker. + */ + private boolean missingQueuesFatal = false; + public Integer getConsumersPerQueue() { return this.consumersPerQueue; } @@ -723,6 +733,15 @@ public class RabbitProperties { this.consumersPerQueue = consumersPerQueue; } + @Override + public boolean isMissingQueuesFatal() { + return this.missingQueuesFatal; + } + + public void setMissingQueuesFatal(boolean missingQueuesFatal) { + this.missingQueuesFatal = missingQueuesFatal; + } + } public static class Template { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java index c94a0185247..4e6ecea329c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java @@ -469,8 +469,8 @@ public class RabbitAutoConfigurationTests { "spring.rabbitmq.listener.simple.prefetch:40", "spring.rabbitmq.listener.simple.defaultRequeueRejected:false", "spring.rabbitmq.listener.simple.idleEventInterval:5", - "spring.rabbitmq.listener.simple.missingQueuesFatal:false", - "spring.rabbitmq.listener.simple.transactionSize:20") + "spring.rabbitmq.listener.simple.transactionSize:20", + "spring.rabbitmq.listener.simple.missingQueuesFatal:false") .run((context) -> { SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context .getBean("rabbitListenerContainerFactory", @@ -481,6 +481,8 @@ public class RabbitAutoConfigurationTests { assertThat(dfa.getPropertyValue("maxConcurrentConsumers")) .isEqualTo(10); assertThat(dfa.getPropertyValue("txSize")).isEqualTo(20); + assertThat(dfa.getPropertyValue("missingQueuesFatal")) + .isEqualTo(false); checkCommonProps(context, dfa); }); } @@ -502,7 +504,7 @@ public class RabbitAutoConfigurationTests { "spring.rabbitmq.listener.direct.prefetch:40", "spring.rabbitmq.listener.direct.defaultRequeueRejected:false", "spring.rabbitmq.listener.direct.idleEventInterval:5", - "spring.rabbitmq.listener.direct.missingQueuesFatal:false") + "spring.rabbitmq.listener.direct.missingQueuesFatal:true") .run((context) -> { DirectRabbitListenerContainerFactory rabbitListenerContainerFactory = context .getBean("rabbitListenerContainerFactory", @@ -510,6 +512,8 @@ public class RabbitAutoConfigurationTests { DirectFieldAccessor dfa = new DirectFieldAccessor( rabbitListenerContainerFactory); assertThat(dfa.getPropertyValue("consumersPerQueue")).isEqualTo(5); + assertThat(dfa.getPropertyValue("missingQueuesFatal")) + .isEqualTo(true); checkCommonProps(context, dfa); }); } @@ -626,7 +630,6 @@ public class RabbitAutoConfigurationTests { assertThat(dfa.getPropertyValue("defaultRequeueRejected")) .isEqualTo(Boolean.FALSE); assertThat(dfa.getPropertyValue("idleEventInterval")).isEqualTo(5L); - assertThat(dfa.getPropertyValue("missingQueuesFatal")).isEqualTo(false); Advice[] adviceChain = (Advice[]) dfa.getPropertyValue("adviceChain"); assertThat(adviceChain).isNotNull(); assertThat(adviceChain.length).isEqualTo(1); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java index 8d0d046e414..1872ce191a9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java @@ -18,6 +18,12 @@ package org.springframework.boot.autoconfigure.amqp; import org.junit.Test; +import org.springframework.amqp.rabbit.config.DirectRabbitListenerContainerFactory; +import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; +import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer; +import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; +import org.springframework.beans.DirectFieldAccessor; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -25,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Dave Syer * @author Andy Wilkinson + * @author Stephane Nicoll */ public class RabbitPropertiesTests { @@ -226,4 +233,28 @@ public class RabbitPropertiesTests { .isEqualTo("rabbit.example.com:1234"); } + @Test + public void simpleContainerUseConsistentDefaultValues() { + SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); + SimpleMessageListenerContainer container = factory.createListenerContainer(); + DirectFieldAccessor dfa = new DirectFieldAccessor(container); + RabbitProperties.SimpleContainer simple = this.properties.getListener() + .getSimple(); + assertThat(simple.isAutoStartup()).isEqualTo(container.isAutoStartup()); + assertThat(simple.isMissingQueuesFatal()) + .isEqualTo(dfa.getPropertyValue("missingQueuesFatal")); + } + + @Test + public void directContainerUseConsistentDefaultValues() { + DirectRabbitListenerContainerFactory factory = new DirectRabbitListenerContainerFactory(); + DirectMessageListenerContainer container = factory.createListenerContainer(); + DirectFieldAccessor dfa = new DirectFieldAccessor(container); + RabbitProperties.DirectContainer direct = this.properties.getListener() + .getDirect(); + assertThat(direct.isAutoStartup()).isEqualTo(container.isAutoStartup()); + assertThat(direct.isMissingQueuesFatal()) + .isEqualTo(dfa.getPropertyValue("missingQueuesFatal")); + } + } diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index e3ed7cc7cf6..648cef76b4a 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -1137,7 +1137,7 @@ content into your application. Rather, pick only the properties that you need. spring.rabbitmq.listener.direct.consumers-per-queue= # Number of consumers per queue. spring.rabbitmq.listener.direct.default-requeue-rejected= # Whether rejected deliveries are re-queued by default. spring.rabbitmq.listener.direct.idle-event-interval= # How often idle container events should be published. - spring.rabbitmq.listener.direct.missing-queues-fatal= # Whether to fail if the queues declared by the container are not available on the broker. + spring.rabbitmq.listener.direct.missing-queues-fatal=false # Whether to fail if the queues declared by the container are not available on the broker. spring.rabbitmq.listener.direct.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.direct.retry.enabled=false # Whether publishing retries are enabled. spring.rabbitmq.listener.direct.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message. @@ -1151,7 +1151,7 @@ content into your application. Rather, pick only the properties that you need. spring.rabbitmq.listener.simple.default-requeue-rejected= # Whether rejected deliveries are re-queued by default. spring.rabbitmq.listener.simple.idle-event-interval= # How often idle container events should be published. spring.rabbitmq.listener.simple.max-concurrency= # Maximum number of listener invoker threads. - spring.rabbitmq.listener.simple.missing-queues-fatal= # Whether to fail if the queues declared by the container are not available on the broker. + spring.rabbitmq.listener.simple.missing-queues-fatal=true # Whether to fail if the queues declared by the container are not available on the broker and/or whether to stop the container if one or more queues are deleted at runtime. spring.rabbitmq.listener.simple.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.simple.retry.enabled=false # Whether publishing retries are enabled. spring.rabbitmq.listener.simple.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.