Commit 24051b42 authored by Stephane Nicoll's avatar Stephane Nicoll

Polish "Add support for configuring missingQueuesFatal property"

See gh-14252
parent 9fb10712
......@@ -116,9 +116,7 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer<T extends
if (configuration.getIdleEventInterval() != null) {
factory.setIdleEventInterval(configuration.getIdleEventInterval().toMillis());
}
if (configuration.getMissingQueuesFatal() != null) {
factory.setMissingQueuesFatal(configuration.getMissingQueuesFatal());
}
factory.setMissingQueuesFatal(configuration.isMissingQueuesFatal());
ListenerRetry retryConfig = configuration.getRetry();
if (retryConfig.isEnabled()) {
RetryInterceptorBuilder<?> builder = (retryConfig.isStateless())
......
......@@ -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 {
......
......@@ -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);
......
......@@ -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"));
}
}
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment