From 47ec8630c88395935fff7b9eb3c36c0a572df94d Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Tue, 16 Aug 2016 23:37:30 +0200 Subject: [PATCH 1/2] Add Rabbit idleEventInterval property This commit adds a property to configure how often idle container events should be published. See gh-6666 --- .../boot/autoconfigure/amqp/RabbitProperties.java | 13 +++++++++++++ ...pleRabbitListenerContainerFactoryConfigurer.java | 3 +++ .../amqp/RabbitAutoConfigurationTests.java | 2 ++ 3 files changed, 18 insertions(+) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index 44750b1c443..b20d1075c75 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -503,6 +503,11 @@ public class RabbitProperties { */ private Boolean defaultRequeueRejected; + /** + * How often to publish idle container events. + */ + private Long idleEventInterval; + /** * Optional properties for a retry interceptor. */ @@ -565,6 +570,14 @@ public class RabbitProperties { this.defaultRequeueRejected = defaultRequeueRejected; } + public Long getIdleEventInterval() { + return idleEventInterval; + } + + public void setIdleEventInterval(Long idleEventInterval) { + this.idleEventInterval = idleEventInterval; + } + public ListenerRetry getRetry() { return this.retry; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java index 037e86601bb..a54835a50b7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/SimpleRabbitListenerContainerFactoryConfigurer.java @@ -90,6 +90,9 @@ public final class SimpleRabbitListenerContainerFactoryConfigurer { if (listenerConfig.getDefaultRequeueRejected() != null) { factory.setDefaultRequeueRejected(listenerConfig.getDefaultRequeueRejected()); } + if (listenerConfig.getIdleEventInterval() != null) { + factory.setIdleEventInterval(listenerConfig.getIdleEventInterval()); + } ListenerRetry retryConfig = listenerConfig.getRetry(); if (retryConfig.isEnabled()) { RetryInterceptorBuilder builder = (retryConfig.isStateless() diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java index a0c54db8fdc..bc9c877fbef 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java @@ -303,6 +303,7 @@ public class RabbitAutoConfigurationTests { "spring.rabbitmq.listener.maxConcurrency:10", "spring.rabbitmq.listener.prefetch:40", "spring.rabbitmq.listener.defaultRequeueRejected:false", + "spring.rabbitmq.listener.idleEventInterval:5", "spring.rabbitmq.listener.transactionSize:20"); SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context .getBean("rabbitListenerContainerFactory", @@ -319,6 +320,7 @@ public class RabbitAutoConfigurationTests { .isSameAs(this.context.getBean("myMessageConverter")); assertThat(dfa.getPropertyValue("defaultRequeueRejected")) .isEqualTo(Boolean.FALSE); + assertThat(dfa.getPropertyValue("idleEventInterval")).isEqualTo(5L); Advice[] adviceChain = (Advice[]) dfa.getPropertyValue("adviceChain"); assertThat(adviceChain).isNotNull(); assertThat(adviceChain.length).isEqualTo(1); From 6fb53f90e5d498af1f762e67e3457919d3560574 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 11 Oct 2016 17:03:10 +0200 Subject: [PATCH 2/2] Polish contribution Closes gh-6666 --- .../boot/autoconfigure/amqp/RabbitProperties.java | 4 ++-- .../src/main/asciidoc/appendix-application-properties.adoc | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index b20d1075c75..929b6afadbb 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -504,7 +504,7 @@ public class RabbitProperties { private Boolean defaultRequeueRejected; /** - * How often to publish idle container events. + * How often idle container events should be published in milliseconds. */ private Long idleEventInterval; @@ -571,7 +571,7 @@ public class RabbitProperties { } public Long getIdleEventInterval() { - return idleEventInterval; + return this.idleEventInterval; } public void setIdleEventInterval(Long idleEventInterval) { diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 3b8f47ff601..c570ffb9bff 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -863,6 +863,7 @@ content into your application; rather pick only the properties that you need. spring.rabbitmq.listener.auto-startup=true # Start the container automatically on startup. spring.rabbitmq.listener.concurrency= # Minimum number of consumers. spring.rabbitmq.listener.default-requeue-rejected= # Whether or not to requeue delivery failures; default `true`. + spring.rabbitmq.idle-event-interval= # How often idle container events should be published in milliseconds. spring.rabbitmq.listener.max-concurrency= # Maximum number of consumers. spring.rabbitmq.listener.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.retry.enabled=false # Whether or not publishing retries are enabled.