Skip to content

feat: add property spring.cloud.aws.sqs.listener.auto-startup to define if sqs listeners should start up automatically #1435

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -93,11 +93,12 @@
|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>
|spring.cloud.aws.sqs.enabled | `+++true+++` | Enables SQS integration.
|spring.cloud.aws.sqs.endpoint | | Overrides the default endpoint.
|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.
|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-delay-between-polls | | The maximum amount of time to wait between consecutive polls to SQS.
|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.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 @@ -874,6 +874,7 @@ The Spring Boot Starter for SQS provides the following auto-configuration proper
| <<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.listener.auto-startup` | Defines whether SQS listeners are started automatically or not. | No | true
| `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
| `spring.cloud.aws.sqs.observation-enabled` | Enables observability support for SQS operations. | No | false
|===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private void configureProperties(SqsContainerOptionsBuilder options) {
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);
mapper.from(this.sqsProperties.getListener().getAutoStartup()).to(options::autoStartup);
}

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

/**
* Defines whether SQS listeners will start automatically or not.
*/
@Nullable
private Boolean autoStartup;

@Nullable
public Integer getMaxConcurrentMessages() {
return this.maxConcurrentMessages;
Expand Down Expand Up @@ -138,6 +144,15 @@ public Duration getMaxDelayBetweenPolls() {
public void setMaxDelayBetweenPolls(Duration maxDelayBetweenPolls) {
this.maxDelayBetweenPolls = maxDelayBetweenPolls;
}

@Nullable
public Boolean getAutoStartup() {
return autoStartup;
}

public void setAutoStartup(Boolean autoStartup) {
this.autoStartup = autoStartup;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ void configuresFactoryComponentsAndOptions() {
"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.max-delay-between-polls:15s")
"spring.cloud.aws.sqs.listener.max-delay-between-polls:15s",
"spring.cloud.aws.sqs.listener.auto-startup=false")
.withUserConfiguration(CustomComponentsConfiguration.class, ObjectMapperConfiguration.class).run(context -> {
assertThat(context).hasSingleBean(SqsMessageListenerContainerFactory.class);
SqsMessageListenerContainerFactory<?> factory = context
Expand All @@ -254,6 +255,7 @@ void configuresFactoryComponentsAndOptions() {
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(8);
assertThat(options.getPollTimeout()).isEqualTo(Duration.ofSeconds(6));
assertThat(options.getMaxDelayBetweenPolls()).isEqualTo(Duration.ofSeconds(15));
assertThat(options.isAutoStartup()).isEqualTo(false);
})
.extracting("messageConverter")
.asInstanceOf(type(SqsMessagingMessageConverter.class))
Expand Down Expand Up @@ -282,6 +284,7 @@ void configuresFactoryComponentsAndOptionsWithDefaults() {
assertThat(options.getMaxMessagesPerPoll()).isEqualTo(10);
assertThat(options.getPollTimeout()).isEqualTo(Duration.ofSeconds(10));
assertThat(options.getMaxDelayBetweenPolls()).isEqualTo(Duration.ofSeconds(10));
assertThat(options.isAutoStartup()).isTrue();
})
.extracting("messageConverter")
.asInstanceOf(type(SqsMessagingMessageConverter.class))
Expand Down