Skip to content

Commit 89bc6f2

Browse files
authored
Add autoconfiguration for maxDelayBetweenPolls (#1365)
* SQS: Add autoconfiguration for maxDelayBetweenPolls (#1354) - Added configuration property to SqsProperties - Added mapping for SqsContainerOptions.maxDelayBetweenPolls in SqsAutoConfiguration for configuring properties in SqsMessageListenerContainerFactory - Included the test for new property in SqsAutoConfigurationTest - Added docs for the new property max-delay-between-polls Closes #1354 * SQS: Add test assertion for default maxDelayBetweenPolls
1 parent 79ac8be commit 89bc6f2

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

docs/src/main/asciidoc/_configprops.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595
|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.
9696
|spring.cloud.aws.sqs.listener.max-messages-per-poll | | The maximum number of messages to be retrieved in a single poll to SQS.
9797
|spring.cloud.aws.sqs.listener.poll-timeout | | The maximum amount of time for a poll to SQS.
98-
|spring.cloud.aws.sqs.queue-not-found-strategy | |
98+
|spring.cloud.aws.sqs.listener.max-delay-between-polls | | The maximum amount of time to wait between consecutive polls to SQS.
99+
|spring.cloud.aws.sqs.queue-not-found-strategy | |
99100
|spring.cloud.aws.sqs.region | | Overrides the default region.
100101

101102
|===

docs/src/main/asciidoc/sqs.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ The Spring Boot Starter for SQS provides the following auto-configuration proper
816816
| <<maxConcurrentMessages, `spring.cloud.aws.sqs.listener.max-inflight-messages-per-queue`>> | Maximum number of inflight messages per queue. | No | 10
817817
| <<maxMessagesPerPoll, `spring.cloud.aws.sqs.listener.max-messages-per-poll`>> | Maximum number of messages to be received per poll. | No | 10
818818
| <<pollTimeout, `spring.cloud.aws.sqs.listener.poll-timeout`>> | Maximum amount of time to wait for messages in a poll. | No | 10 seconds
819+
| <<maxDelayBetweenPolls, `spring.cloud.aws.sqs.listener.max-delay-between-polls`>> | Maximum amount of time to wait between polls. | No | 10 seconds
819820
| `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
820821
|===
821822

spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/sqs/SqsAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private void configureProperties(SqsContainerOptionsBuilder options) {
136136
mapper.from(this.sqsProperties.getListener().getMaxConcurrentMessages()).to(options::maxConcurrentMessages);
137137
mapper.from(this.sqsProperties.getListener().getMaxMessagesPerPoll()).to(options::maxMessagesPerPoll);
138138
mapper.from(this.sqsProperties.getListener().getPollTimeout()).to(options::pollTimeout);
139+
mapper.from(this.sqsProperties.getListener().getMaxDelayBetweenPolls()).to(options::maxDelayBetweenPolls);
139140
}
140141

141142
@Bean

spring-cloud-aws-autoconfigure/src/main/java/io/awspring/cloud/autoconfigure/sqs/SqsProperties.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ public static class Listener {
8787
@Nullable
8888
private Duration pollTimeout;
8989

90+
/**
91+
* The maximum amount of time to wait between consecutive polls to SQS.
92+
*/
93+
@Nullable
94+
private Duration maxDelayBetweenPolls;
95+
9096
@Nullable
9197
public Integer getMaxConcurrentMessages() {
9298
return this.maxConcurrentMessages;
@@ -113,6 +119,15 @@ public Duration getPollTimeout() {
113119
public void setPollTimeout(Duration pollTimeout) {
114120
this.pollTimeout = pollTimeout;
115121
}
122+
123+
@Nullable
124+
public Duration getMaxDelayBetweenPolls() {
125+
return maxDelayBetweenPolls;
126+
}
127+
128+
public void setMaxDelayBetweenPolls(Duration maxDelayBetweenPolls) {
129+
this.maxDelayBetweenPolls = maxDelayBetweenPolls;
130+
}
116131
}
117132

118133
}

spring-cloud-aws-autoconfigure/src/test/java/io/awspring/cloud/autoconfigure/sqs/SqsAutoConfigurationTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ void configuresFactoryComponentsAndOptions() {
152152
.withPropertyValues("spring.cloud.aws.sqs.enabled:true",
153153
"spring.cloud.aws.sqs.listener.max-concurrent-messages:19",
154154
"spring.cloud.aws.sqs.listener.max-messages-per-poll:8",
155-
"spring.cloud.aws.sqs.listener.poll-timeout:6s")
155+
"spring.cloud.aws.sqs.listener.poll-timeout:6s",
156+
"spring.cloud.aws.sqs.listener.max-delay-between-polls:15s")
156157
.withUserConfiguration(CustomComponentsConfiguration.class, ObjectMapperConfiguration.class).run(context -> {
157158
assertThat(context).hasSingleBean(SqsMessageListenerContainerFactory.class);
158159
SqsMessageListenerContainerFactory<?> factory = context
@@ -168,6 +169,7 @@ void configuresFactoryComponentsAndOptions() {
168169
assertThat(options.getMaxConcurrentMessages()).isEqualTo(19);
169170
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(8);
170171
assertThat(options.getPollTimeout()).isEqualTo(Duration.ofSeconds(6));
172+
assertThat(options.getMaxDelayBetweenPolls()).isEqualTo(Duration.ofSeconds(15));
171173
})
172174
.extracting("messageConverter")
173175
.asInstanceOf(type(SqsMessagingMessageConverter.class))
@@ -195,6 +197,7 @@ void configuresFactoryComponentsAndOptionsWithDefaults() {
195197
assertThat(options.getMaxConcurrentMessages()).isEqualTo(10);
196198
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(10);
197199
assertThat(options.getPollTimeout()).isEqualTo(Duration.ofSeconds(10));
200+
assertThat(options.getMaxDelayBetweenPolls()).isEqualTo(Duration.ofSeconds(10));
198201
})
199202
.extracting("messageConverter")
200203
.asInstanceOf(type(SqsMessagingMessageConverter.class))

0 commit comments

Comments
 (0)