Skip to content

Commit 09b57ef

Browse files
nosansnicoll
authored andcommitted
Add option for configuring max messages per task
See gh-42341
1 parent e133ea3 commit 09b57ef

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/DefaultJmsListenerContainerFactoryConfigurer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public void configure(DefaultJmsListenerContainerFactory factory, ConnectionFact
135135
map.from(listenerProperties::isAutoStartup).to(factory::setAutoStartup);
136136
map.from(listenerProperties::formatConcurrency).to(factory::setConcurrency);
137137
map.from(listenerProperties::getReceiveTimeout).as(Duration::toMillis).to(factory::setReceiveTimeout);
138+
map.from(listenerProperties::getMaxMessagesPerTask).to(factory::setMaxMessagesPerTask);
138139
}
139140

140141
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ public static class Listener {
186186
*/
187187
private Duration receiveTimeout = Duration.ofSeconds(1);
188188

189+
/**
190+
* Specify the maximum number of messages to process in one task.
191+
*/
192+
private Integer maxMessagesPerTask;
193+
189194
private final Session session = new Session();
190195

191196
public boolean isAutoStartup() {
@@ -250,6 +255,14 @@ public void setReceiveTimeout(Duration receiveTimeout) {
250255
this.receiveTimeout = receiveTimeout;
251256
}
252257

258+
public Integer getMaxMessagesPerTask() {
259+
return this.maxMessagesPerTask;
260+
}
261+
262+
public void setMaxMessagesPerTask(Integer maxMessagesPerTask) {
263+
this.maxMessagesPerTask = maxMessagesPerTask;
264+
}
265+
253266
public Session getSession() {
254267
return this.session;
255268
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ void testJmsListenerContainerFactoryWithCustomSettings() {
176176
"spring.jms.listener.session.acknowledgeMode=client",
177177
"spring.jms.listener.session.transacted=false", "spring.jms.listener.minConcurrency=2",
178178
"spring.jms.listener.receiveTimeout=2s", "spring.jms.listener.maxConcurrency=10",
179-
"spring.jms.subscription-durable=true", "spring.jms.client-id=exampleId")
179+
"spring.jms.subscription-durable=true", "spring.jms.client-id=exampleId",
180+
"spring.jms.listener.max-messages-per-task=10")
180181
.run(this::testJmsListenerContainerFactoryWithCustomSettings);
181182
}
182183

@@ -188,6 +189,7 @@ private void testJmsListenerContainerFactoryWithCustomSettings(AssertableApplica
188189
assertThat(container.getConcurrentConsumers()).isEqualTo(2);
189190
assertThat(container.getMaxConcurrentConsumers()).isEqualTo(10);
190191
assertThat(container).hasFieldOrPropertyWithValue("receiveTimeout", 2000L);
192+
assertThat(container).hasFieldOrPropertyWithValue("maxMessagesPerTask", 10);
191193
assertThat(container.isSubscriptionDurable()).isTrue();
192194
assertThat(container.getClientId()).isEqualTo("exampleId");
193195
}

0 commit comments

Comments
 (0)