Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spring.jms.listener.max-messages-per-task property for configuring max messages per task #42341

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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");
}
Expand Down