Skip to content

Commit 9f043a3

Browse files
committed
Remove SQS batch configuration support and simplify ReceiveMessageRequest handling.
1 parent f42e019 commit 9f043a3

File tree

4 files changed

+5
-335
lines changed

4 files changed

+5
-335
lines changed

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

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
import io.awspring.cloud.autoconfigure.AwsClientProperties;
1919
import io.awspring.cloud.sqs.listener.QueueNotFoundStrategy;
2020
import java.time.Duration;
21-
import java.util.List;
2221
import org.springframework.boot.context.properties.ConfigurationProperties;
2322
import org.springframework.lang.Nullable;
24-
import software.amazon.awssdk.services.sqs.model.MessageSystemAttributeName;
2523

2624
/**
2725
* Properties related to AWS SQS.
@@ -40,8 +38,6 @@ public class SqsProperties extends AwsClientProperties {
4038

4139
private Listener listener = new Listener();
4240

43-
private Batch batch = new Batch();
44-
4541
public Listener getListener() {
4642
return this.listener;
4743
}
@@ -50,14 +46,6 @@ public void setListener(Listener listener) {
5046
this.listener = listener;
5147
}
5248

53-
public Batch getBatch() {
54-
return batch;
55-
}
56-
57-
public void setBatch(Batch batch) {
58-
this.batch = batch;
59-
}
60-
6149
@Nullable
6250
private QueueNotFoundStrategy queueNotFoundStrategy;
6351

@@ -165,155 +153,6 @@ public Boolean getAutoStartup() {
165153
public void setAutoStartup(Boolean autoStartup) {
166154
this.autoStartup = autoStartup;
167155
}
168-
169-
}
170-
171-
/**
172-
* Configuration properties for SQS automatic batching using AWS SDK's {@code SqsAsyncBatchManager}.
173-
*
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.
178-
*
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.
183-
*
184-
* @since 3.2
185-
*/
186-
public static class Batch {
187-
188-
/**
189-
* Enables SQS automatic batching using AWS SDK's SqsAsyncBatchManager.
190-
*
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.
195-
*
196-
* <p>
197-
* Default is {@code false}.
198-
*/
199-
private boolean enabled = false;
200-
201-
/**
202-
* The maximum number of messages that can be processed in a single batch. The maximum is 10.
203-
*/
204-
@Nullable
205-
private Integer maxNumberOfMessages;
206-
207-
/**
208-
* The frequency at which requests are sent to SQS when processing messages in a batch.
209-
*/
210-
@Nullable
211-
private Duration sendBatchFrequency;
212-
213-
/**
214-
* The visibility timeout to set for messages received in a batch. If unset, the queue default is used.
215-
*/
216-
@Nullable
217-
private Duration visibilityTimeout;
218-
219-
/**
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.
222-
*/
223-
@Nullable
224-
private Duration waitTimeSeconds;
225-
226-
/**
227-
* The list of system attribute names to request for receiveMessage calls.
228-
*/
229-
@Nullable
230-
private List<MessageSystemAttributeName> systemAttributeNames;
231-
232-
/**
233-
* The list of attribute names to request for receiveMessage calls.
234-
*/
235-
@Nullable
236-
private List<String> attributeNames;
237-
238-
/**
239-
* The size of the scheduled thread pool used for batching operations. This thread pool handles periodic batch
240-
* sending and other scheduled tasks.
241-
*
242-
* <p>
243-
* Default is {@code 5}.
244-
*/
245-
private int scheduledExecutorPoolSize = 5;
246-
247-
public boolean isEnabled() {
248-
return enabled;
249-
}
250-
251-
public void setEnabled(boolean enabled) {
252-
this.enabled = enabled;
253-
}
254-
255-
@Nullable
256-
public Integer getMaxNumberOfMessages() {
257-
return maxNumberOfMessages;
258-
}
259-
260-
public void setMaxNumberOfMessages(Integer maxNumberOfMessages) {
261-
this.maxNumberOfMessages = maxNumberOfMessages;
262-
}
263-
264-
@Nullable
265-
public Duration getSendBatchFrequency() {
266-
return sendBatchFrequency;
267-
}
268-
269-
public void setSendBatchFrequency(Duration sendBatchFrequency) {
270-
this.sendBatchFrequency = sendBatchFrequency;
271-
}
272-
273-
@Nullable
274-
public Duration getVisibilityTimeout() {
275-
return visibilityTimeout;
276-
}
277-
278-
public void setVisibilityTimeout(Duration visibilityTimeout) {
279-
this.visibilityTimeout = visibilityTimeout;
280-
}
281-
282-
@Nullable
283-
public Duration getWaitTimeSeconds() {
284-
return waitTimeSeconds;
285-
}
286-
287-
public void setWaitTimeSeconds(Duration waitTimeSeconds) {
288-
this.waitTimeSeconds = waitTimeSeconds;
289-
}
290-
291-
@Nullable
292-
public List<MessageSystemAttributeName> getSystemAttributeNames() {
293-
return systemAttributeNames;
294-
}
295-
296-
public void setSystemAttributeNames(List<MessageSystemAttributeName> systemAttributeNames) {
297-
this.systemAttributeNames = systemAttributeNames;
298-
}
299-
300-
@Nullable
301-
public List<String> getAttributeNames() {
302-
return attributeNames;
303-
}
304-
305-
public void setAttributeNames(List<String> attributeNames) {
306-
this.attributeNames = attributeNames;
307-
}
308-
309-
public int getScheduledExecutorPoolSize() {
310-
return scheduledExecutorPoolSize;
311-
}
312-
313-
public void setScheduledExecutorPoolSize(int scheduledExecutorPoolSize) {
314-
this.scheduledExecutorPoolSize = scheduledExecutorPoolSize;
315-
}
316-
317156
}
318157

319158
}

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

Lines changed: 0 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import io.awspring.cloud.sqs.listener.QueueNotFoundStrategy;
3434
import io.awspring.cloud.sqs.listener.errorhandler.AsyncErrorHandler;
3535
import io.awspring.cloud.sqs.listener.interceptor.AsyncMessageInterceptor;
36-
import io.awspring.cloud.sqs.operations.BatchingSqsClientAdapter;
3736
import io.awspring.cloud.sqs.operations.SqsTemplate;
3837
import io.awspring.cloud.sqs.support.converter.MessagingMessageConverter;
3938
import io.awspring.cloud.sqs.support.converter.SqsMessagingMessageConverter;
@@ -61,7 +60,6 @@
6160
*
6261
* @author Tomaz Fernandes
6362
* @author Wei Jiang
64-
* @author Heechul Kang
6563
*/
6664
class SqsAutoConfigurationTest {
6765

@@ -305,166 +303,6 @@ void configuresMessageConverter() {
305303
});
306304
}
307305

308-
@Test
309-
void sqsBatchAutoConfigurationIsDisabledByDefault() {
310-
this.contextRunner.run(context -> {
311-
assertThat(context).hasSingleBean(SqsAsyncClient.class);
312-
SqsAsyncClient client = context.getBean(SqsAsyncClient.class);
313-
assertThat(client).isNotInstanceOf(BatchingSqsClientAdapter.class);
314-
});
315-
}
316-
317-
@Test
318-
void sqsBatchAutoConfigurationIsEnabled() {
319-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:true").run(context -> {
320-
assertThat(context.getBeansOfType(SqsAsyncClient.class)).hasSize(2);
321-
322-
SqsAsyncClient primary = context.getBean(SqsAsyncClient.class);
323-
assertThat(primary).isInstanceOf(BatchingSqsClientAdapter.class);
324-
325-
assertThat(context).hasBean("sqsAsyncClient");
326-
assertThat(context).hasBean("batchSqsAsyncClient");
327-
});
328-
}
329-
330-
@Test
331-
void sqsBatchConfigurationProperties() {
332-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:true",
333-
"spring.cloud.aws.sqs.batch.max-number-of-messages:5",
334-
"spring.cloud.aws.sqs.batch.send-batch-frequency:PT0.5S").run(context -> {
335-
SqsAsyncClient client = context.getBean(SqsAsyncClient.class);
336-
assertThat(client).isInstanceOf(BatchingSqsClientAdapter.class);
337-
});
338-
}
339-
340-
@Test
341-
void sqsBatchConfigurationPropertiesWithAllSettings() {
342-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:true",
343-
"spring.cloud.aws.sqs.batch.max-number-of-messages:8",
344-
"spring.cloud.aws.sqs.batch.send-batch-frequency:PT1S",
345-
"spring.cloud.aws.sqs.batch.visibility-timeout:PT30S",
346-
"spring.cloud.aws.sqs.batch.wait-time-seconds:PT5S",
347-
"spring.cloud.aws.sqs.batch.system-attribute-names:SentTimestamp,ApproximateReceiveCount",
348-
"spring.cloud.aws.sqs.batch.attribute-names:attr1,attr2").run(context -> {
349-
assertThat(context).hasSingleBean(SqsProperties.class);
350-
SqsProperties sqsProperties = context.getBean(SqsProperties.class);
351-
SqsProperties.Batch batchConfig = sqsProperties.getBatch();
352-
353-
assertThat(batchConfig.isEnabled()).isTrue();
354-
assertThat(batchConfig.getMaxNumberOfMessages()).isEqualTo(8);
355-
assertThat(batchConfig.getSendBatchFrequency()).isEqualTo(Duration.ofSeconds(1));
356-
assertThat(batchConfig.getVisibilityTimeout()).isEqualTo(Duration.ofSeconds(30));
357-
assertThat(batchConfig.getWaitTimeSeconds()).isEqualTo(Duration.ofSeconds(5));
358-
assertThat(batchConfig.getSystemAttributeNames()).containsExactly(
359-
software.amazon.awssdk.services.sqs.model.MessageSystemAttributeName.SENT_TIMESTAMP,
360-
software.amazon.awssdk.services.sqs.model.MessageSystemAttributeName.APPROXIMATE_RECEIVE_COUNT);
361-
assertThat(batchConfig.getAttributeNames()).containsExactly("attr1", "attr2");
362-
363-
SqsAsyncClient client = context.getBean(SqsAsyncClient.class);
364-
assertThat(client).isInstanceOf(BatchingSqsClientAdapter.class);
365-
});
366-
}
367-
368-
@Test
369-
void sqsBatchConfigurationPropertiesWithDefaults() {
370-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:false").run(context -> {
371-
assertThat(context).hasSingleBean(SqsProperties.class);
372-
SqsProperties sqsProperties = context.getBean(SqsProperties.class);
373-
SqsProperties.Batch batchConfig = sqsProperties.getBatch();
374-
375-
assertThat(batchConfig.isEnabled()).isFalse();
376-
assertThat(batchConfig.getMaxNumberOfMessages()).isNull();
377-
assertThat(batchConfig.getSendBatchFrequency()).isNull();
378-
assertThat(batchConfig.getVisibilityTimeout()).isNull();
379-
assertThat(batchConfig.getWaitTimeSeconds()).isNull();
380-
assertThat(batchConfig.getSystemAttributeNames()).isNull();
381-
assertThat(batchConfig.getAttributeNames()).isNull();
382-
assertThat(batchConfig.getScheduledExecutorPoolSize()).isEqualTo(5);
383-
384-
assertThat(context).hasSingleBean(SqsAsyncClient.class);
385-
SqsAsyncClient client = context.getBean(SqsAsyncClient.class);
386-
assertThat(client).isNotInstanceOf(BatchingSqsClientAdapter.class);
387-
});
388-
}
389-
390-
@Test
391-
void sqsBatchConfigurationWithVisibilityTimeout() {
392-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:true",
393-
"spring.cloud.aws.sqs.batch.visibility-timeout:PT60S").run(context -> {
394-
assertThat(context).hasSingleBean(SqsProperties.class);
395-
SqsProperties sqsProperties = context.getBean(SqsProperties.class);
396-
SqsProperties.Batch batchConfig = sqsProperties.getBatch();
397-
398-
assertThat(batchConfig.isEnabled()).isTrue();
399-
assertThat(batchConfig.getVisibilityTimeout()).isEqualTo(Duration.ofSeconds(60));
400-
});
401-
}
402-
403-
@Test
404-
void sqsBatchConfigurationWithWaitTimeSeconds() {
405-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:true",
406-
"spring.cloud.aws.sqs.batch.wait-time-seconds:PT20S").run(context -> {
407-
assertThat(context).hasSingleBean(SqsProperties.class);
408-
SqsProperties sqsProperties = context.getBean(SqsProperties.class);
409-
SqsProperties.Batch batchConfig = sqsProperties.getBatch();
410-
411-
assertThat(batchConfig.isEnabled()).isTrue();
412-
assertThat(batchConfig.getWaitTimeSeconds()).isEqualTo(Duration.ofSeconds(20));
413-
});
414-
}
415-
416-
@Test
417-
void sqsBatchConfigurationWithAttributeNames() {
418-
this.contextRunner
419-
.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:true",
420-
"spring.cloud.aws.sqs.batch.attribute-names:MessageGroupId,MessageDeduplicationId")
421-
.run(context -> {
422-
assertThat(context).hasSingleBean(SqsProperties.class);
423-
SqsProperties sqsProperties = context.getBean(SqsProperties.class);
424-
SqsProperties.Batch batchConfig = sqsProperties.getBatch();
425-
426-
assertThat(batchConfig.isEnabled()).isTrue();
427-
assertThat(batchConfig.getAttributeNames()).containsExactly("MessageGroupId",
428-
"MessageDeduplicationId");
429-
});
430-
}
431-
432-
@Test
433-
void sqsBatchConfigurationWithDefaultScheduledExecutorPoolSize() {
434-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:true").run(context -> {
435-
assertThat(context).hasSingleBean(SqsProperties.class);
436-
SqsProperties sqsProperties = context.getBean(SqsProperties.class);
437-
SqsProperties.Batch batchConfig = sqsProperties.getBatch();
438-
439-
assertThat(batchConfig.isEnabled()).isTrue();
440-
assertThat(batchConfig.getScheduledExecutorPoolSize()).isEqualTo(5);
441-
442-
assertThat(context).hasBean("sqsBatchingScheduledExecutor");
443-
});
444-
}
445-
446-
@Test
447-
void sqsBatchConfigurationWithCustomScheduledExecutorPoolSize() {
448-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:true",
449-
"spring.cloud.aws.sqs.batch.scheduled-executor-pool-size:10").run(context -> {
450-
assertThat(context).hasSingleBean(SqsProperties.class);
451-
SqsProperties sqsProperties = context.getBean(SqsProperties.class);
452-
SqsProperties.Batch batchConfig = sqsProperties.getBatch();
453-
454-
assertThat(batchConfig.isEnabled()).isTrue();
455-
assertThat(batchConfig.getScheduledExecutorPoolSize()).isEqualTo(10);
456-
457-
assertThat(context).hasBean("sqsBatchingScheduledExecutor");
458-
});
459-
}
460-
461-
@Test
462-
void sqsBatchConfigurationWithBatchDisabledDoesNotCreateScheduledExecutor() {
463-
this.contextRunner.withPropertyValues("spring.cloud.aws.sqs.batch.enabled:false").run(context -> {
464-
assertThat(context).doesNotHaveBean("sqsBatchingScheduledExecutor");
465-
});
466-
}
467-
468306
@Configuration(proxyBeanMethods = false)
469307
static class CustomComponentsConfiguration {
470308

0 commit comments

Comments
 (0)