Skip to content

Commit 91e731a

Browse files
nosansnicoll
authored andcommitted
Add support for configuring missingQueuesFatal property
See gh-14252
1 parent b5e113c commit 91e731a

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
@@ -665,6 +665,13 @@ public static class SimpleContainer extends AmqpContainer {
665665
*/
666666
private Integer transactionSize;
667667

668+
/**
669+
* Whether the context should be ended up with failure if there are no any queues
670+
* available on the broker or the container should be stopped if queues have been
671+
* removed while the container is running.
672+
*/
673+
private Boolean missingQueuesFatal;
674+
668675
public Integer getConcurrency() {
669676
return this.concurrency;
670677
}
@@ -689,6 +696,14 @@ public void setTransactionSize(Integer transactionSize) {
689696
this.transactionSize = transactionSize;
690697
}
691698

699+
public Boolean getMissingQueuesFatal() {
700+
return this.missingQueuesFatal;
701+
}
702+
703+
public void setMissingQueuesFatal(Boolean missingQueuesFatal) {
704+
this.missingQueuesFatal = missingQueuesFatal;
705+
}
706+
692707
}
693708

694709
/**
@@ -701,6 +716,12 @@ public static class DirectContainer extends AmqpContainer {
701716
*/
702717
private Integer consumersPerQueue;
703718

719+
/**
720+
* Whether the context should be ended up with failure if there are no any queues
721+
* available on the broker.
722+
*/
723+
private Boolean missingQueuesFatal;
724+
704725
public Integer getConsumersPerQueue() {
705726
return this.consumersPerQueue;
706727
}
@@ -709,6 +730,14 @@ public void setConsumersPerQueue(Integer consumersPerQueue) {
709730
this.consumersPerQueue = consumersPerQueue;
710731
}
711732

733+
public Boolean getMissingQueuesFatal() {
734+
return this.missingQueuesFatal;
735+
}
736+
737+
public void setMissingQueuesFatal(Boolean missingQueuesFatal) {
738+
this.missingQueuesFatal = missingQueuesFatal;
739+
}
740+
712741
}
713742

714743
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
@@ -468,6 +468,7 @@ public void testSimpleRabbitListenerContainerFactoryWithCustomSettings() {
468468
"spring.rabbitmq.listener.simple.maxConcurrency:10",
469469
"spring.rabbitmq.listener.simple.prefetch:40",
470470
"spring.rabbitmq.listener.simple.defaultRequeueRejected:false",
471+
"spring.rabbitmq.listener.simple.missingQueuesFatal:false",
471472
"spring.rabbitmq.listener.simple.idleEventInterval:5",
472473
"spring.rabbitmq.listener.simple.transactionSize:20")
473474
.run((context) -> {
@@ -500,6 +501,7 @@ public void testDirectRabbitListenerContainerFactoryWithCustomSettings() {
500501
"spring.rabbitmq.listener.direct.consumers-per-queue:5",
501502
"spring.rabbitmq.listener.direct.prefetch:40",
502503
"spring.rabbitmq.listener.direct.defaultRequeueRejected:false",
504+
"spring.rabbitmq.listener.direct.missingQueuesFatal:false",
503505
"spring.rabbitmq.listener.direct.idleEventInterval:5")
504506
.run((context) -> {
505507
DirectRabbitListenerContainerFactory rabbitListenerContainerFactory = context
@@ -621,6 +623,7 @@ private void checkCommonProps(AssertableApplicationContext context,
621623
assertThat(dfa.getPropertyValue("prefetchCount")).isEqualTo(40);
622624
assertThat(dfa.getPropertyValue("messageConverter"))
623625
.isSameAs(context.getBean("myMessageConverter"));
626+
assertThat(dfa.getPropertyValue("missingQueuesFatal")).isEqualTo(false);
624627
assertThat(dfa.getPropertyValue("defaultRequeueRejected"))
625628
.isEqualTo(Boolean.FALSE);
626629
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
@@ -1137,6 +1137,7 @@ content into your application. Rather, pick only the properties that you need.
11371137
spring.rabbitmq.listener.direct.consumers-per-queue= # Number of consumers per queue.
11381138
spring.rabbitmq.listener.direct.default-requeue-rejected= # Whether rejected deliveries are re-queued by default.
11391139
spring.rabbitmq.listener.direct.idle-event-interval= # How often idle container events should be published.
1140+
spring.rabbitmq.listener.direct.missing-queues-fatal= # Whether the context should be ended up with failure if there are no any queues available on the broker.
11401141
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).
11411142
spring.rabbitmq.listener.direct.retry.enabled=false # Whether publishing retries are enabled.
11421143
spring.rabbitmq.listener.direct.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.
@@ -1150,6 +1151,7 @@ content into your application. Rather, pick only the properties that you need.
11501151
spring.rabbitmq.listener.simple.default-requeue-rejected= # Whether rejected deliveries are re-queued by default.
11511152
spring.rabbitmq.listener.simple.idle-event-interval= # How often idle container events should be published.
11521153
spring.rabbitmq.listener.simple.max-concurrency= # Maximum number of listener invoker threads.
1154+
spring.rabbitmq.listener.simple.missing-queues-fatal= # Whether the context should be ended up with failure if there are no any queues available on the broker or the container should be stopped if queues have been removed while the container is running.
11531155
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).
11541156
spring.rabbitmq.listener.simple.retry.enabled=false # Whether publishing retries are enabled.
11551157
spring.rabbitmq.listener.simple.retry.initial-interval=1000ms # Duration between the first and second attempt to deliver a message.

0 commit comments

Comments
 (0)