From 1f875d552ac98353d6c6eabeb8473772414d0a77 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 5 Sep 2019 21:41:47 +0100 Subject: [PATCH] Polish "Add a config property for JMS listener container's receive timeout" See gh-17332 --- .../boot/autoconfigure/jms/JmsProperties.java | 9 ++++----- .../boot/autoconfigure/jms/JmsPropertiesTests.java | 8 ++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java index 14e24d36ea..aafab7c8fd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java @@ -156,12 +156,11 @@ public class JmsProperties { private Integer maxConcurrency; /** - * Timeout to use for receive calls. By default, the listener uses a 1s timeout on - * its polling loop. See - * @see org.springframework.jms.listener.AbstractPollingMessageListenerContainer#setReceiveTimeout - * for more details on this value and the meaning of special values 0 and -1. + * Timeout to use for receive calls. Use -1 for a no-wait receive or 0 for no + * timeout at all. The latter is only feasible if not running within a transaction + * manager and is generally discouraged since it prevents clean shutdown. */ - private Duration receiveTimeout; + private Duration receiveTimeout = Duration.ofSeconds(1); public boolean isAutoStartup() { return this.autoStartup; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsPropertiesTests.java index ae4d4ac54b..2f339d7670 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsPropertiesTests.java @@ -20,6 +20,8 @@ import java.time.Duration; import org.junit.jupiter.api.Test; +import org.springframework.jms.listener.AbstractPollingMessageListenerContainer; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -78,4 +80,10 @@ class JmsPropertiesTests { assertThat(properties.getTemplate().determineQosEnabled()).isTrue(); } + @Test + void defaultReceiveTimeoutMatchesListenerContainersDefault() { + assertThat(new JmsProperties().getListener().getReceiveTimeout()) + .isEqualTo(Duration.ofMillis(AbstractPollingMessageListenerContainer.DEFAULT_RECEIVE_TIMEOUT)); + } + }