diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java index 66ab3db1ee6c..be9d767d0f26 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java @@ -135,6 +135,7 @@ public void configure(DefaultJmsListenerContainerFactory factory, ConnectionFact map.from(listenerProperties::isAutoStartup).to(factory::setAutoStartup); map.from(listenerProperties::formatConcurrency).to(factory::setConcurrency); map.from(listenerProperties::getReceiveTimeout).as(Duration::toMillis).to(factory::setReceiveTimeout); + map.from(listenerProperties::getMaxMessagesPerTask).to(factory::setMaxMessagesPerTask); } } 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 7d87ec9169cb..051c12ef6b81 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 @@ -186,6 +186,11 @@ public static class Listener { */ private Duration receiveTimeout = Duration.ofSeconds(1); + /** + * Specify the maximum number of messages to process in one task. + */ + private Integer maxMessagesPerTask; + private final Session session = new Session(); public boolean isAutoStartup() { @@ -250,6 +255,14 @@ public void setReceiveTimeout(Duration receiveTimeout) { this.receiveTimeout = receiveTimeout; } + public Integer getMaxMessagesPerTask() { + return this.maxMessagesPerTask; + } + + public void setMaxMessagesPerTask(Integer maxMessagesPerTask) { + this.maxMessagesPerTask = maxMessagesPerTask; + } + public Session getSession() { return this.session; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java index 906b9f390ffd..91d0589e7591 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java @@ -176,7 +176,8 @@ void testJmsListenerContainerFactoryWithCustomSettings() { "spring.jms.listener.session.acknowledgeMode=client", "spring.jms.listener.session.transacted=false", "spring.jms.listener.minConcurrency=2", "spring.jms.listener.receiveTimeout=2s", "spring.jms.listener.maxConcurrency=10", - "spring.jms.subscription-durable=true", "spring.jms.client-id=exampleId") + "spring.jms.subscription-durable=true", "spring.jms.client-id=exampleId", + "spring.jms.listener.max-messages-per-task=10") .run(this::testJmsListenerContainerFactoryWithCustomSettings); } @@ -188,6 +189,7 @@ private void testJmsListenerContainerFactoryWithCustomSettings(AssertableApplica assertThat(container.getConcurrentConsumers()).isEqualTo(2); assertThat(container.getMaxConcurrentConsumers()).isEqualTo(10); assertThat(container).hasFieldOrPropertyWithValue("receiveTimeout", 2000L); + assertThat(container).hasFieldOrPropertyWithValue("maxMessagesPerTask", 10); assertThat(container.isSubscriptionDurable()).isTrue(); assertThat(container.getClientId()).isEqualTo("exampleId"); }