Add a config property for JMS listener container's receive timeout

See gh-17332
pull/18164/head
ibmmqmet 5 years ago committed by Andy Wilkinson
parent 52479ee04f
commit 1cde657861

@ -16,6 +16,8 @@
package org.springframework.boot.autoconfigure.jms;
import java.time.Duration;
import javax.jms.ConnectionFactory;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
@ -107,6 +109,10 @@ public final class DefaultJmsListenerContainerFactoryConfigurer {
if (concurrency != null) {
factory.setConcurrency(concurrency);
}
Duration receiveTimeout = listener.getReceiveTimeout();
if (receiveTimeout != null) {
factory.setReceiveTimeout(receiveTimeout.toMillis());
}
}
}

@ -155,6 +155,14 @@ 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.
*/
private Duration receiveTimeout;
public boolean isAutoStartup() {
return this.autoStartup;
}
@ -195,6 +203,14 @@ public class JmsProperties {
: String.valueOf(this.concurrency));
}
public Duration getReceiveTimeout() {
return this.receiveTimeout;
}
public void setReceiveTimeout(Duration receiveTimeout) {
this.receiveTimeout = receiveTimeout;
}
}
public static class Template {

@ -147,7 +147,7 @@ class JmsAutoConfigurationTests {
this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)
.withPropertyValues("spring.jms.listener.autoStartup=false",
"spring.jms.listener.acknowledgeMode=client", "spring.jms.listener.concurrency=2",
"spring.jms.listener.maxConcurrency=10")
"spring.jms.listener.receiveTimeout=2s", "spring.jms.listener.maxConcurrency=10")
.run(this::testJmsListenerContainerFactoryWithCustomSettings);
}
@ -157,6 +157,18 @@ class JmsAutoConfigurationTests {
assertThat(container.getSessionAcknowledgeMode()).isEqualTo(Session.CLIENT_ACKNOWLEDGE);
assertThat(container.getConcurrentConsumers()).isEqualTo(2);
assertThat(container.getMaxConcurrentConsumers()).isEqualTo(10);
assertThat(container).hasFieldOrPropertyWithValue("receiveTimeout", 2000L);
}
@Test
void testJmsListenerContainerFactoryWithDefaultSettings() {
this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)
.run(this::testJmsListenerContainerFactoryWithDefaultSettings);
}
private void testJmsListenerContainerFactoryWithDefaultSettings(AssertableApplicationContext loaded) {
DefaultMessageListenerContainer container = getContainer(loaded, "jmsListenerContainerFactory");
assertThat(container).hasFieldOrPropertyWithValue("receiveTimeout", 1000L);
}
@Test

Loading…
Cancel
Save