Skip to content

Commit a13275f

Browse files
committed
If all of the configured queue(s) are not available on the broker, this setting determines whether the condition is fatal. When true, and the queues are missing during startup, the context refresh() will fail.
When false, the condition is not considered fatal and the container will continue to attempt to start the consumers. -- Only for SimpleRabbitListenerContainerFactoryConfigurer When true, if the queues are removed while the container is running, the container is stopped. closes gh-14122
1 parent 6c26315 commit a13275f

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/DirectRabbitListenerContainerFactoryConfigurer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public void configure(DirectRabbitListenerContainerFactory factory,
4040
configure(factory, connectionFactory, config);
4141
map.from(config::getConsumersPerQueue).whenNonNull()
4242
.to(factory::setConsumersPerQueue);
43+
map.from(config::getMissingQueuesFatal).whenNonNull()
44+
.to(factory::setMissingQueuesFatal);
4345
}
4446

4547
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@ public static class SimpleContainer extends AmqpContainer {
639639
*/
640640
private Integer transactionSize;
641641

642+
/**
643+
* Should the context end up with failure if there are no any queues in the
644+
* broker, or the container must be stopped when the queues have been removed
645+
* while the container is running.
646+
*/
647+
private Boolean missingQueuesFatal;
648+
642649
public Integer getConcurrency() {
643650
return this.concurrency;
644651
}
@@ -663,6 +670,14 @@ public void setTransactionSize(Integer transactionSize) {
663670
this.transactionSize = transactionSize;
664671
}
665672

673+
public Boolean getMissingQueuesFatal() {
674+
return this.missingQueuesFatal;
675+
}
676+
677+
public void setMissingQueuesFatal(Boolean missingQueuesFatal) {
678+
this.missingQueuesFatal = missingQueuesFatal;
679+
}
680+
666681
}
667682

668683
/**
@@ -675,6 +690,12 @@ public static class DirectContainer extends AmqpContainer {
675690
*/
676691
private Integer consumersPerQueue;
677692

693+
/**
694+
* Should the context end up with failure if there are no any queues in the
695+
* broker.
696+
*/
697+
private Boolean missingQueuesFatal;
698+
678699
public Integer getConsumersPerQueue() {
679700
return this.consumersPerQueue;
680701
}
@@ -683,6 +704,14 @@ public void setConsumersPerQueue(Integer consumersPerQueue) {
683704
this.consumersPerQueue = consumersPerQueue;
684705
}
685706

707+
public Boolean getMissingQueuesFatal() {
708+
return this.missingQueuesFatal;
709+
}
710+
711+
public void setMissingQueuesFatal(Boolean missingQueuesFatal) {
712+
this.missingQueuesFatal = missingQueuesFatal;
713+
}
714+
686715
}
687716

688717
public static class Template {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public void configure(SimpleRabbitListenerContainerFactory factory,
4343
map.from(config::getMaxConcurrency).whenNonNull()
4444
.to(factory::setMaxConcurrentConsumers);
4545
map.from(config::getTransactionSize).whenNonNull().to(factory::setTxSize);
46+
map.from(config::getMissingQueuesFatal).whenNonNull()
47+
.to(factory::setMissingQueuesFatal);
4648
}
4749

4850
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ public void testSimpleRabbitListenerContainerFactoryWithCustomSettings() {
464464
"spring.rabbitmq.listener.simple.maxConcurrency:10",
465465
"spring.rabbitmq.listener.simple.prefetch:40",
466466
"spring.rabbitmq.listener.simple.defaultRequeueRejected:false",
467+
"spring.rabbitmq.listener.simple.missingQueuesFatal:false",
467468
"spring.rabbitmq.listener.simple.idleEventInterval:5",
468469
"spring.rabbitmq.listener.simple.transactionSize:20")
469470
.run((context) -> {
@@ -496,6 +497,7 @@ public void testDirectRabbitListenerContainerFactoryWithCustomSettings() {
496497
"spring.rabbitmq.listener.direct.consumers-per-queue:5",
497498
"spring.rabbitmq.listener.direct.prefetch:40",
498499
"spring.rabbitmq.listener.direct.defaultRequeueRejected:false",
500+
"spring.rabbitmq.listener.direct.missingQueuesFatal:false",
499501
"spring.rabbitmq.listener.direct.idleEventInterval:5")
500502
.run((context) -> {
501503
DirectRabbitListenerContainerFactory rabbitListenerContainerFactory = context
@@ -617,6 +619,7 @@ private void checkCommonProps(AssertableApplicationContext context,
617619
assertThat(dfa.getPropertyValue("prefetchCount")).isEqualTo(40);
618620
assertThat(dfa.getPropertyValue("messageConverter"))
619621
.isSameAs(context.getBean("myMessageConverter"));
622+
assertThat(dfa.getPropertyValue("missingQueuesFatal")).isEqualTo(false);
620623
assertThat(dfa.getPropertyValue("defaultRequeueRejected"))
621624
.isEqualTo(Boolean.FALSE);
622625
assertThat(dfa.getPropertyValue("idleEventInterval")).isEqualTo(5L);

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ content into your application. Rather, pick only the properties that you need.
11381138
spring.rabbitmq.listener.direct.consumers-per-queue= # Number of consumers per queue.
11391139
spring.rabbitmq.listener.direct.default-requeue-rejected= # Whether rejected deliveries are re-queued by default.
11401140
spring.rabbitmq.listener.direct.idle-event-interval= # How often idle container events should be published.
1141+
spring.rabbitmq.listener.direct.missing-queues-fatal= # Should the context end up with failure if there are no any queues in the broker.
11411142
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).
11421143
spring.rabbitmq.listener.direct.retry.enabled=false # Whether publishing retries are enabled.
11431144
spring.rabbitmq.listener.direct.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
@@ -1151,6 +1152,7 @@ content into your application. Rather, pick only the properties that you need.
11511152
spring.rabbitmq.listener.simple.default-requeue-rejected= # Whether rejected deliveries are re-queued by default.
11521153
spring.rabbitmq.listener.simple.idle-event-interval= # How often idle container events should be published.
11531154
spring.rabbitmq.listener.simple.max-concurrency= # Maximum number of listener invoker threads.
1155+
spring.rabbitmq.listener.simple.missing-queues-fatal= # Should the context end up with failure if there are no any queues in the broker, or the container must be stopped when the queues have been removed while the container is running.
11541156
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).
11551157
spring.rabbitmq.listener.simple.retry.enabled=false # Whether publishing retries are enabled.
11561158
spring.rabbitmq.listener.simple.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.

0 commit comments

Comments
 (0)