Skip to content

Commit 12ad251

Browse files
committed
refactor: clean up code formatting and improve readability in SqsTemplate, SqsProperties, and BatchingSqsClientAdapter
1 parent cc6b1fc commit 12ad251

File tree

7 files changed

+750
-819
lines changed

7 files changed

+750
-819
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: 24 additions & 25 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
*
@@ -172,14 +171,15 @@ public void setAutoStartup(Boolean autoStartup) {
172171
/**
173172
* Configuration properties for SQS automatic batching using AWS SDK's {@code SqsAsyncBatchManager}.
174173
*
175-
* <p>Automatic batching improves performance and reduces costs by combining multiple SQS requests
176-
* into fewer AWS API calls. When enabled, Spring Cloud AWS will use a {@code BatchingSqsClientAdapter}
177-
* that wraps the standard {@code SqsAsyncClient} with batching capabilities.
174+
* <p>
175+
* Automatic batching improves performance and reduces costs by combining multiple SQS requests into fewer AWS API
176+
* calls. When enabled, Spring Cloud AWS will use a {@code BatchingSqsClientAdapter} that wraps the standard
177+
* {@code SqsAsyncClient} with batching capabilities.
178178
*
179-
* <p><strong>Important:</strong> Batched operations are processed asynchronously, which may result
180-
* in false positives where method calls appear to succeed locally but fail during actual transmission
181-
* to AWS. Applications should handle the returned {@code CompletableFuture} objects to detect
182-
* actual transmission errors.
179+
* <p>
180+
* <strong>Important:</strong> Batched operations are processed asynchronously, which may result in false positives
181+
* where method calls appear to succeed locally but fail during actual transmission to AWS. Applications should
182+
* handle the returned {@code CompletableFuture} objects to detect actual transmission errors.
183183
*
184184
* @since 3.2
185185
*/
@@ -188,38 +188,37 @@ public static class Batch {
188188
/**
189189
* Enables SQS automatic batching using AWS SDK's SqsAsyncBatchManager.
190190
*
191-
* <p>When set to {@code true}, the {@code SqsAsyncClient} bean will be wrapped
192-
* with a {@code BatchingSqsClientAdapter} that automatically batches requests
193-
* to improve performance and reduce AWS API calls.
191+
* <p>
192+
* When set to {@code true}, the {@code SqsAsyncClient} bean will be wrapped with a
193+
* {@code BatchingSqsClientAdapter} that automatically batches requests to improve performance and reduce AWS
194+
* API calls.
194195
*
195-
* <p>Default is {@code false}.
196+
* <p>
197+
* Default is {@code false}.
196198
*/
197199
private boolean enabled = false;
198200

199201
/**
200-
* The maximum number of messages that can be processed in a single batch. The
201-
* maximum is 10.
202+
* The maximum number of messages that can be processed in a single batch. The maximum is 10.
202203
*/
203204
@Nullable
204205
private Integer maxNumberOfMessages;
205206

206207
/**
207-
* The frequency at which requests are sent to SQS when processing messages in a
208-
* batch.
208+
* The frequency at which requests are sent to SQS when processing messages in a batch.
209209
*/
210210
@Nullable
211211
private Duration sendBatchFrequency;
212212

213213
/**
214-
* The visibility timeout to set for messages received in a batch. If unset, the
215-
* queue default is used.
214+
* The visibility timeout to set for messages received in a batch. If unset, the queue default is used.
216215
*/
217216
@Nullable
218217
private Duration visibilityTimeout;
219218

220219
/**
221-
* The minimum wait duration for a receiveMessage request in a batch. To avoid
222-
* unnecessary CPU usage, do not set this value to 0.
220+
* The minimum wait duration for a receiveMessage request in a batch. To avoid unnecessary CPU usage, do not set
221+
* this value to 0.
223222
*/
224223
@Nullable
225224
private Duration waitTimeSeconds;
@@ -240,9 +239,9 @@ public boolean isEnabled() {
240239
return enabled;
241240
}
242241

243-
public void setEnabled(boolean enabled) {
244-
this.enabled = enabled;
245-
}
242+
public void setEnabled(boolean enabled) {
243+
this.enabled = enabled;
244+
}
246245

247246
@Nullable
248247
public Integer getMaxNumberOfMessages() {

0 commit comments

Comments
 (0)