Skip to content

Commit 903ca09

Browse files
authored
feat: add property spring.cloud.aws.sqs.listener.auto-startup to define if sqs listeners should start up automatically (#1435)
FIXES gh-1188 Co-authored-by: techadri <[email protected]>
1 parent 332555e commit 903ca09

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
@@ -93,11 +93,12 @@
9393
|spring.cloud.aws.sqs.dualstack-enabled | | Configure whether the AWS client should use the AWS dualstack endpoint. Note that not each AWS service supports dual-stack. For complete list check <a href="https://docs.aws.amazon.com/vpc/latest/userguide/aws-ipv6-support.html">AWS services that support IPv6</a>
9494
|spring.cloud.aws.sqs.enabled | `+++true+++` | Enables SQS integration.
9595
|spring.cloud.aws.sqs.endpoint | | Overrides the default endpoint.
96+
|spring.cloud.aws.sqs.listener.auto-startup | | Configure whether SQS listeners are started automatically or not. If set to false, the listener containers need to be started manually.
9697
|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.
9798
|spring.cloud.aws.sqs.listener.max-delay-between-polls | | The maximum amount of time to wait between consecutive polls to SQS.
9899
|spring.cloud.aws.sqs.listener.max-messages-per-poll | | The maximum number of messages to be retrieved in a single poll to SQS.
99100
|spring.cloud.aws.sqs.listener.poll-timeout | | The maximum amount of time for a poll to SQS.
100101
|spring.cloud.aws.sqs.queue-not-found-strategy | |
101102
|spring.cloud.aws.sqs.region | | Overrides the default region.
102103

103-
|===
104+
|===

docs/src/main/asciidoc/sqs.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ The Spring Boot Starter for SQS provides the following auto-configuration proper
874874
| <<maxMessagesPerPoll, `spring.cloud.aws.sqs.listener.max-messages-per-poll`>> | Maximum number of messages to be received per poll. | No | 10
875875
| <<pollTimeout, `spring.cloud.aws.sqs.listener.poll-timeout`>> | Maximum amount of time to wait for messages in a poll. | No | 10 seconds
876876
| <<maxDelayBetweenPolls, `spring.cloud.aws.sqs.listener.max-delay-between-polls`>> | Maximum amount of time to wait between polls. | No | 10 seconds
877+
| `spring.cloud.aws.sqs.listener.auto-startup` | Defines whether SQS listeners are started automatically or not. | No | true
877878
| `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
878879
| `spring.cloud.aws.sqs.observation-enabled` | Enables observability support for SQS operations. | No | false
879880
|===

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
@@ -156,6 +156,7 @@ private void configureProperties(SqsContainerOptionsBuilder options) {
156156
mapper.from(this.sqsProperties.getListener().getMaxMessagesPerPoll()).to(options::maxMessagesPerPoll);
157157
mapper.from(this.sqsProperties.getListener().getPollTimeout()).to(options::pollTimeout);
158158
mapper.from(this.sqsProperties.getListener().getMaxDelayBetweenPolls()).to(options::maxDelayBetweenPolls);
159+
mapper.from(this.sqsProperties.getListener().getAutoStartup()).to(options::autoStartup);
159160
}
160161

161162
@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
@@ -103,6 +103,12 @@ public static class Listener {
103103
@Nullable
104104
private Duration maxDelayBetweenPolls;
105105

106+
/**
107+
* Defines whether SQS listeners will start automatically or not.
108+
*/
109+
@Nullable
110+
private Boolean autoStartup;
111+
106112
@Nullable
107113
public Integer getMaxConcurrentMessages() {
108114
return this.maxConcurrentMessages;
@@ -138,6 +144,15 @@ public Duration getMaxDelayBetweenPolls() {
138144
public void setMaxDelayBetweenPolls(Duration maxDelayBetweenPolls) {
139145
this.maxDelayBetweenPolls = maxDelayBetweenPolls;
140146
}
147+
148+
@Nullable
149+
public Boolean getAutoStartup() {
150+
return autoStartup;
151+
}
152+
153+
public void setAutoStartup(Boolean autoStartup) {
154+
this.autoStartup = autoStartup;
155+
}
141156
}
142157

143158
}

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
@@ -237,7 +237,8 @@ void configuresFactoryComponentsAndOptions() {
237237
"spring.cloud.aws.sqs.listener.max-concurrent-messages:19",
238238
"spring.cloud.aws.sqs.listener.max-messages-per-poll:8",
239239
"spring.cloud.aws.sqs.listener.poll-timeout:6s",
240-
"spring.cloud.aws.sqs.listener.max-delay-between-polls:15s")
240+
"spring.cloud.aws.sqs.listener.max-delay-between-polls:15s",
241+
"spring.cloud.aws.sqs.listener.auto-startup=false")
241242
.withUserConfiguration(CustomComponentsConfiguration.class, ObjectMapperConfiguration.class).run(context -> {
242243
assertThat(context).hasSingleBean(SqsMessageListenerContainerFactory.class);
243244
SqsMessageListenerContainerFactory<?> factory = context
@@ -254,6 +255,7 @@ void configuresFactoryComponentsAndOptions() {
254255
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(8);
255256
assertThat(options.getPollTimeout()).isEqualTo(Duration.ofSeconds(6));
256257
assertThat(options.getMaxDelayBetweenPolls()).isEqualTo(Duration.ofSeconds(15));
258+
assertThat(options.isAutoStartup()).isEqualTo(false);
257259
})
258260
.extracting("messageConverter")
259261
.asInstanceOf(type(SqsMessagingMessageConverter.class))
@@ -282,6 +284,7 @@ void configuresFactoryComponentsAndOptionsWithDefaults() {
282284
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(10);
283285
assertThat(options.getPollTimeout()).isEqualTo(Duration.ofSeconds(10));
284286
assertThat(options.getMaxDelayBetweenPolls()).isEqualTo(Duration.ofSeconds(10));
287+
assertThat(options.isAutoStartup()).isTrue();
285288
})
286289
.extracting("messageConverter")
287290
.asInstanceOf(type(SqsMessagingMessageConverter.class))

0 commit comments

Comments
 (0)