Skip to content

Commit 76b7fe8

Browse files
committed
refactor: clean up code formatting and improve readability in SqsTemplate, SqsProperties, and BatchingSqsClientAdapter
1 parent 608ce77 commit 76b7fe8

File tree

7 files changed

+752
-822
lines changed

7 files changed

+752
-822
lines changed

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

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import io.awspring.cloud.sqs.support.observation.SqsListenerObservation;
3535
import io.awspring.cloud.sqs.support.observation.SqsTemplateObservation;
3636
import io.micrometer.observation.ObservationRegistry;
37+
import java.util.concurrent.Executors;
3738
import org.springframework.beans.factory.ObjectProvider;
3839
import org.springframework.boot.autoconfigure.AutoConfiguration;
3940
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -52,8 +53,6 @@
5253
import software.amazon.awssdk.services.sqs.batchmanager.SqsAsyncBatchManager;
5354
import software.amazon.awssdk.services.sqs.model.Message;
5455

55-
import java.util.concurrent.Executors;
56-
5756
/**
5857
* {@link EnableAutoConfiguration Auto-configuration} for SQS integration.
5958
*
@@ -84,10 +83,10 @@ public SqsAsyncClient sqsAsyncClient(AwsClientBuilderConfigurer awsClientBuilder
8483
ObjectProvider<AwsConnectionDetails> connectionDetails,
8584
ObjectProvider<SqsAsyncClientCustomizer> sqsAsyncClientCustomizers,
8685
ObjectProvider<AwsAsyncClientCustomizer> awsAsyncClientCustomizers) {
87-
return awsClientBuilderConfigurer.configureAsyncClient(SqsAsyncClient.builder(), this.sqsProperties,
88-
connectionDetails.getIfAvailable(), configurer.getIfAvailable(),
89-
sqsAsyncClientCustomizers.orderedStream(), awsAsyncClientCustomizers.orderedStream()).build();
90-
}
86+
return awsClientBuilderConfigurer.configureAsyncClient(SqsAsyncClient.builder(), this.sqsProperties,
87+
connectionDetails.getIfAvailable(), configurer.getIfAvailable(),
88+
sqsAsyncClientCustomizers.orderedStream(), awsAsyncClientCustomizers.orderedStream()).build();
89+
}
9190

9291
@ConditionalOnProperty(name = "spring.cloud.aws.sqs.batch.enabled", havingValue = "true")
9392
@Bean
@@ -98,11 +97,9 @@ public SqsAsyncClient batchSqsAsyncClient(SqsAsyncClient sqsAsyncClient) {
9897
}
9998

10099
private SqsAsyncBatchManager createBatchManager(SqsAsyncClient sqsAsyncClient) {
101-
return SqsAsyncBatchManager.builder()
102-
.client(sqsAsyncClient)
103-
.scheduledExecutor(Executors.newScheduledThreadPool(5))
104-
.overrideConfiguration(this::configurationProperties)
105-
.build();
100+
return SqsAsyncBatchManager.builder().client(sqsAsyncClient)
101+
.scheduledExecutor(Executors.newScheduledThreadPool(5))
102+
.overrideConfiguration(this::configurationProperties).build();
106103
}
107104

108105
private void configurationProperties(BatchOverrideConfiguration.Builder options) {
@@ -112,7 +109,7 @@ private void configurationProperties(BatchOverrideConfiguration.Builder options)
112109
mapper.from(this.sqsProperties.getBatch().getWaitTimeSeconds()).to(options::receiveMessageMinWaitDuration);
113110
mapper.from(this.sqsProperties.getBatch().getVisibilityTimeout()).to(options::receiveMessageVisibilityTimeout);
114111
mapper.from(this.sqsProperties.getBatch().getSystemAttributeNames())
115-
.to(options::receiveMessageSystemAttributeNames);
112+
.to(options::receiveMessageSystemAttributeNames);
116113
mapper.from(this.sqsProperties.getBatch().getAttributeNames()).to(options::receiveMessageAttributeNames);
117114
}
118115

@@ -122,15 +119,15 @@ public SqsTemplate sqsTemplate(SqsAsyncClient sqsAsyncClient, ObjectProvider<Obj
122119
ObjectProvider<ObservationRegistry> observationRegistryProvider,
123120
ObjectProvider<SqsTemplateObservation.Convention> observationConventionProvider,
124121
MessagingMessageConverter<Message> messageConverter) {
125-
SqsTemplateBuilder builder = SqsTemplate.builder().sqsAsyncClient(sqsAsyncClient)
126-
.messageConverter(messageConverter);
122+
SqsTemplateBuilder builder = SqsTemplate.builder().sqsAsyncClient(sqsAsyncClient)
123+
.messageConverter(messageConverter);
127124
objectMapperProvider.ifAvailable(om -> setMapperToConverter(messageConverter, om));
128-
if (this.sqsProperties.isObservationEnabled()) {
129-
observationRegistryProvider
130-
.ifAvailable(registry -> builder.configure(options -> options.observationRegistry(registry)));
131-
observationConventionProvider
132-
.ifAvailable(convention -> builder.configure(options -> options.observationConvention(convention)));
133-
}
125+
if (this.sqsProperties.isObservationEnabled()) {
126+
observationRegistryProvider
127+
.ifAvailable(registry -> builder.configure(options -> options.observationRegistry(registry)));
128+
observationConventionProvider
129+
.ifAvailable(convention -> builder.configure(options -> options.observationConvention(convention)));
130+
}
134131
if (sqsProperties.getQueueNotFoundStrategy() != null) {
135132
builder.configure((options) -> options.queueNotFoundStrategy(sqsProperties.getQueueNotFoundStrategy()));
136133
}
@@ -156,12 +153,12 @@ public SqsMessageListenerContainerFactory<Object> defaultSqsListenerContainerFac
156153
interceptors.forEach(factory::addMessageInterceptor);
157154
asyncInterceptors.forEach(factory::addMessageInterceptor);
158155
objectMapperProvider.ifAvailable(om -> setMapperToConverter(messagingMessageConverter, om));
159-
if (this.sqsProperties.isObservationEnabled()) {
160-
observationRegistry
161-
.ifAvailable(registry -> factory.configure(options -> options.observationRegistry(registry)));
162-
observationConventionProvider
163-
.ifAvailable(convention -> factory.configure(options -> options.observationConvention(convention)));
164-
}
156+
if (this.sqsProperties.isObservationEnabled()) {
157+
observationRegistry
158+
.ifAvailable(registry -> factory.configure(options -> options.observationRegistry(registry)));
159+
observationConventionProvider
160+
.ifAvailable(convention -> factory.configure(options -> options.observationConvention(convention)));
161+
}
165162
factory.configure(options -> options.messageConverter(messagingMessageConverter));
166163
return factory;
167164
}

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

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717

1818
import io.awspring.cloud.autoconfigure.AwsClientProperties;
1919
import io.awspring.cloud.sqs.listener.QueueNotFoundStrategy;
20+
import java.time.Duration;
21+
import java.util.List;
2022
import org.springframework.boot.context.properties.ConfigurationProperties;
2123
import org.springframework.lang.Nullable;
2224
import software.amazon.awssdk.services.sqs.model.MessageSystemAttributeName;
2325

24-
import java.time.Duration;
25-
import java.util.List;
26-
2726
/**
2827
* Properties related to AWS SQS.
2928
*
@@ -92,9 +91,8 @@ public void setObservationEnabled(Boolean observationEnabled) {
9291
public static class Listener {
9392

9493
/**
95-
* The maximum concurrent messages that can be processed simultaneously for each
96-
* queue. Note that if acknowledgement batching is being used, the actual maximum
97-
* number of messages inflight might be higher.
94+
* The maximum concurrent messages that can be processed simultaneously for each queue. Note that if
95+
* acknowledgement batching is being used, the actual maximum number of messages inflight might be higher.
9896
*/
9997
@Nullable
10098
private Integer maxConcurrentMessages;
@@ -158,14 +156,15 @@ public void setMaxDelayBetweenPolls(Duration maxDelayBetweenPolls) {
158156
/**
159157
* Configuration properties for SQS automatic batching using AWS SDK's {@code SqsAsyncBatchManager}.
160158
*
161-
* <p>Automatic batching improves performance and reduces costs by combining multiple SQS requests
162-
* into fewer AWS API calls. When enabled, Spring Cloud AWS will use a {@code BatchingSqsClientAdapter}
163-
* that wraps the standard {@code SqsAsyncClient} with batching capabilities.
159+
* <p>
160+
* Automatic batching improves performance and reduces costs by combining multiple SQS requests into fewer AWS API
161+
* calls. When enabled, Spring Cloud AWS will use a {@code BatchingSqsClientAdapter} that wraps the standard
162+
* {@code SqsAsyncClient} with batching capabilities.
164163
*
165-
* <p><strong>Important:</strong> Batched operations are processed asynchronously, which may result
166-
* in false positives where method calls appear to succeed locally but fail during actual transmission
167-
* to AWS. Applications should handle the returned {@code CompletableFuture} objects to detect
168-
* actual transmission errors.
164+
* <p>
165+
* <strong>Important:</strong> Batched operations are processed asynchronously, which may result in false positives
166+
* where method calls appear to succeed locally but fail during actual transmission to AWS. Applications should
167+
* handle the returned {@code CompletableFuture} objects to detect actual transmission errors.
169168
*
170169
* @since 3.2
171170
*/
@@ -174,38 +173,37 @@ public static class Batch {
174173
/**
175174
* Enables SQS automatic batching using AWS SDK's SqsAsyncBatchManager.
176175
*
177-
* <p>When set to {@code true}, the {@code SqsAsyncClient} bean will be wrapped
178-
* with a {@code BatchingSqsClientAdapter} that automatically batches requests
179-
* to improve performance and reduce AWS API calls.
176+
* <p>
177+
* When set to {@code true}, the {@code SqsAsyncClient} bean will be wrapped with a
178+
* {@code BatchingSqsClientAdapter} that automatically batches requests to improve performance and reduce AWS
179+
* API calls.
180180
*
181-
* <p>Default is {@code false}.
181+
* <p>
182+
* Default is {@code false}.
182183
*/
183184
private boolean enabled = false;
184185

185186
/**
186-
* The maximum number of messages that can be processed in a single batch. The
187-
* maximum is 10.
187+
* The maximum number of messages that can be processed in a single batch. The maximum is 10.
188188
*/
189189
@Nullable
190190
private Integer maxNumberOfMessages;
191191

192192
/**
193-
* The frequency at which requests are sent to SQS when processing messages in a
194-
* batch.
193+
* The frequency at which requests are sent to SQS when processing messages in a batch.
195194
*/
196195
@Nullable
197196
private Duration sendBatchFrequency;
198197

199198
/**
200-
* The visibility timeout to set for messages received in a batch. If unset, the
201-
* queue default is used.
199+
* The visibility timeout to set for messages received in a batch. If unset, the queue default is used.
202200
*/
203201
@Nullable
204202
private Duration visibilityTimeout;
205203

206204
/**
207-
* The minimum wait duration for a receiveMessage request in a batch. To avoid
208-
* unnecessary CPU usage, do not set this value to 0.
205+
* The minimum wait duration for a receiveMessage request in a batch. To avoid unnecessary CPU usage, do not set
206+
* this value to 0.
209207
*/
210208
@Nullable
211209
private Duration waitTimeSeconds;
@@ -226,9 +224,9 @@ public boolean isEnabled() {
226224
return enabled;
227225
}
228226

229-
public void setEnabled(boolean enabled) {
230-
this.enabled = enabled;
231-
}
227+
public void setEnabled(boolean enabled) {
228+
this.enabled = enabled;
229+
}
232230

233231
@Nullable
234232
public Integer getMaxNumberOfMessages() {

0 commit comments

Comments
 (0)