Skip to content

SQS: Add autoconfiguration for maxDelayBetweenPolls #1365

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

Merged
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
3 changes: 2 additions & 1 deletion docs/src/main/asciidoc/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
|spring.cloud.aws.sqs.listener.max-concurrent-messages | | The maximum concurrent messages that can be processed simultaneously for each queue. Note that if acknowledgement batching is being used, the actual maximum number of messages inflight might be higher.
|spring.cloud.aws.sqs.listener.max-messages-per-poll | | The maximum number of messages to be retrieved in a single poll to SQS.
|spring.cloud.aws.sqs.listener.poll-timeout | | The maximum amount of time for a poll to SQS.
|spring.cloud.aws.sqs.queue-not-found-strategy | |
|spring.cloud.aws.sqs.listener.max-delay-between-polls | | The maximum amount of time to wait between consecutive polls to SQS.
|spring.cloud.aws.sqs.queue-not-found-strategy | |
|spring.cloud.aws.sqs.region | | Overrides the default region.

|===
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/sqs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ The Spring Boot Starter for SQS provides the following auto-configuration proper
| <<maxConcurrentMessages, `spring.cloud.aws.sqs.listener.max-inflight-messages-per-queue`>> | Maximum number of inflight messages per queue. | No | 10
| <<maxMessagesPerPoll, `spring.cloud.aws.sqs.listener.max-messages-per-poll`>> | Maximum number of messages to be received per poll. | No | 10
| <<pollTimeout, `spring.cloud.aws.sqs.listener.poll-timeout`>> | Maximum amount of time to wait for messages in a poll. | No | 10 seconds
| <<maxDelayBetweenPolls, `spring.cloud.aws.sqs.listener.max-delay-between-polls`>> | Maximum amount of time to wait between polls. | No | 10 seconds
| `spring.cloud.aws.sqs.queue-not-found-strategy` | The strategy to be used by SqsTemplate and SqsListeners when a queue does not exist. | No | CREATE
|===

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private void configureProperties(SqsContainerOptionsBuilder options) {
mapper.from(this.sqsProperties.getListener().getMaxConcurrentMessages()).to(options::maxConcurrentMessages);
mapper.from(this.sqsProperties.getListener().getMaxMessagesPerPoll()).to(options::maxMessagesPerPoll);
mapper.from(this.sqsProperties.getListener().getPollTimeout()).to(options::pollTimeout);
mapper.from(this.sqsProperties.getListener().getMaxDelayBetweenPolls()).to(options::maxDelayBetweenPolls);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public static class Listener {
@Nullable
private Duration pollTimeout;

/**
* The maximum amount of time to wait between consecutive polls to SQS.
*/
@Nullable
private Duration maxDelayBetweenPolls;

@Nullable
public Integer getMaxConcurrentMessages() {
return this.maxConcurrentMessages;
Expand All @@ -113,6 +119,15 @@ public Duration getPollTimeout() {
public void setPollTimeout(Duration pollTimeout) {
this.pollTimeout = pollTimeout;
}

@Nullable
public Duration getMaxDelayBetweenPolls() {
return maxDelayBetweenPolls;
}

public void setMaxDelayBetweenPolls(Duration maxDelayBetweenPolls) {
this.maxDelayBetweenPolls = maxDelayBetweenPolls;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ void configuresFactoryComponentsAndOptions() {
.withPropertyValues("spring.cloud.aws.sqs.enabled:true",
"spring.cloud.aws.sqs.listener.max-concurrent-messages:19",
"spring.cloud.aws.sqs.listener.max-messages-per-poll:8",
"spring.cloud.aws.sqs.listener.poll-timeout:6s")
"spring.cloud.aws.sqs.listener.poll-timeout:6s",
"spring.cloud.aws.sqs.listener.max-delay-between-polls:15s")
.withUserConfiguration(CustomComponentsConfiguration.class, ObjectMapperConfiguration.class).run(context -> {
assertThat(context).hasSingleBean(SqsMessageListenerContainerFactory.class);
SqsMessageListenerContainerFactory<?> factory = context
Expand All @@ -168,6 +169,7 @@ void configuresFactoryComponentsAndOptions() {
assertThat(options.getMaxConcurrentMessages()).isEqualTo(19);
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(8);
assertThat(options.getPollTimeout()).isEqualTo(Duration.ofSeconds(6));
assertThat(options.getMaxDelayBetweenPolls()).isEqualTo(Duration.ofSeconds(15));
})
.extracting("messageConverter")
.asInstanceOf(type(SqsMessagingMessageConverter.class))
Expand Down Expand Up @@ -195,6 +197,7 @@ void configuresFactoryComponentsAndOptionsWithDefaults() {
assertThat(options.getMaxConcurrentMessages()).isEqualTo(10);
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(10);
assertThat(options.getPollTimeout()).isEqualTo(Duration.ofSeconds(10));
assertThat(options.getMaxDelayBetweenPolls()).isEqualTo(Duration.ofSeconds(10));
})
.extracting("messageConverter")
.asInstanceOf(type(SqsMessagingMessageConverter.class))
Expand Down