Add support for configuring missingQueuesFatal property

See gh-14252
This commit is contained in:
Dmytro Nosan
2018-08-30 14:02:44 +03:00
committed by Stephane Nicoll
parent b5e113c64f
commit 91e731a4b4
5 changed files with 38 additions and 0 deletions

View File

@@ -40,6 +40,8 @@ public final class DirectRabbitListenerContainerFactoryConfigurer extends
configure(factory, connectionFactory, config);
map.from(config::getConsumersPerQueue).whenNonNull()
.to(factory::setConsumersPerQueue);
map.from(config::getMissingQueuesFatal).whenNonNull()
.to(factory::setMissingQueuesFatal);
}
}

View File

@@ -665,6 +665,13 @@ public class RabbitProperties {
*/
private Integer transactionSize;
/**
* 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.
*/
private Boolean missingQueuesFatal;
public Integer getConcurrency() {
return this.concurrency;
}
@@ -689,6 +696,14 @@ public class RabbitProperties {
this.transactionSize = transactionSize;
}
public Boolean getMissingQueuesFatal() {
return this.missingQueuesFatal;
}
public void setMissingQueuesFatal(Boolean missingQueuesFatal) {
this.missingQueuesFatal = missingQueuesFatal;
}
}
/**
@@ -701,6 +716,12 @@ public class RabbitProperties {
*/
private Integer consumersPerQueue;
/**
* Whether the context should be ended up with failure if there are no any queues
* available on the broker.
*/
private Boolean missingQueuesFatal;
public Integer getConsumersPerQueue() {
return this.consumersPerQueue;
}
@@ -709,6 +730,14 @@ public class RabbitProperties {
this.consumersPerQueue = consumersPerQueue;
}
public Boolean getMissingQueuesFatal() {
return this.missingQueuesFatal;
}
public void setMissingQueuesFatal(Boolean missingQueuesFatal) {
this.missingQueuesFatal = missingQueuesFatal;
}
}
public static class Template {

View File

@@ -43,6 +43,8 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer extends
map.from(config::getMaxConcurrency).whenNonNull()
.to(factory::setMaxConcurrentConsumers);
map.from(config::getTransactionSize).whenNonNull().to(factory::setTxSize);
map.from(config::getMissingQueuesFatal).whenNonNull()
.to(factory::setMissingQueuesFatal);
}
}

View File

@@ -468,6 +468,7 @@ public class RabbitAutoConfigurationTests {
"spring.rabbitmq.listener.simple.maxConcurrency:10",
"spring.rabbitmq.listener.simple.prefetch:40",
"spring.rabbitmq.listener.simple.defaultRequeueRejected:false",
"spring.rabbitmq.listener.simple.missingQueuesFatal:false",
"spring.rabbitmq.listener.simple.idleEventInterval:5",
"spring.rabbitmq.listener.simple.transactionSize:20")
.run((context) -> {
@@ -500,6 +501,7 @@ public class RabbitAutoConfigurationTests {
"spring.rabbitmq.listener.direct.consumers-per-queue:5",
"spring.rabbitmq.listener.direct.prefetch:40",
"spring.rabbitmq.listener.direct.defaultRequeueRejected:false",
"spring.rabbitmq.listener.direct.missingQueuesFatal:false",
"spring.rabbitmq.listener.direct.idleEventInterval:5")
.run((context) -> {
DirectRabbitListenerContainerFactory rabbitListenerContainerFactory = context
@@ -621,6 +623,7 @@ public class RabbitAutoConfigurationTests {
assertThat(dfa.getPropertyValue("prefetchCount")).isEqualTo(40);
assertThat(dfa.getPropertyValue("messageConverter"))
.isSameAs(context.getBean("myMessageConverter"));
assertThat(dfa.getPropertyValue("missingQueuesFatal")).isEqualTo(false);
assertThat(dfa.getPropertyValue("defaultRequeueRejected"))
.isEqualTo(Boolean.FALSE);
assertThat(dfa.getPropertyValue("idleEventInterval")).isEqualTo(5L);