Class SqsMessageListenerContainer<T>

Type Parameters:
T - the Message payload type. This type is used to ensure at compile time that all components in this container expect the same payload type. If the factory will be used with many payload types, Object can be used.
All Implemented Interfaces:
MessageListenerContainer<T>, Lifecycle, Phased, SmartLifecycle

public class SqsMessageListenerContainer<T> extends AbstractPipelineMessageListenerContainer<T,SqsContainerOptions,SqsContainerOptionsBuilder>
MessageListenerContainer implementation for SQS queues. To create an instance, both constructors or the builder() method can be used, and further configuration can be achieved by using the AbstractMessageListenerContainer.configure(Consumer) method.

The SqsAsyncClient instance to be used by this container must be set through the constructor or the SqsMessageListenerContainer.Builder.sqsAsyncClient method.

The container also accepts the following components:

The non-async components will be adapted to their async counterparts. Components and ContainerOptions can be changed when the container is stopped. Such changes will be effective upon container restart.

Containers created through the SqsListener annotation will be registered in a MessageListenerContainerRegistry which will be responsible for managing their lifecycle. Containers created manually and declared as beans will have their lifecycle managed by Spring Context.

Example using the builder:

 
 @Bean
 public SqsMessageListenerContainer mySqsListenerContainer(SqsAsyncClient sqsAsyncClient) {
     return SqsMessageListenerContainer
             .builder()
             .configure(options -> options
                     .messagesPerPoll(5)
                     .pollTimeout(Duration.ofSeconds(10)))
             .sqsAsyncClient(sqsAsyncClient)
             .build();
 }
 
 

 

Example using the constructor:

 
 @Bean
 public SqsMessageListenerContainer myListenerContainer(SqsAsyncClient sqsAsyncClient) {
     SqsMessageListenerContainer container = new SqsMessageListenerContainer<>(sqsAsyncClient);
     container.configure(options -> options
             .messagesPerPoll(5)
             .pollTimeout(Duration.ofSeconds(10)));
     return container;
 }
 
 
Since:
3.0
Author:
Tomaz Fernandes