Class SqsMessageListenerContainerFactory<T>

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

MessageListenerContainerFactory implementation for creating SqsMessageListenerContainer instances. A factory can be assigned to a @SqsListener by using the SqsListener.factory() property. The factory can also be used to create container instances manually.

To create an instance, both the default constructor or the builder() method can be used, and further configuration can be achieved by using the AbstractMessageListenerContainerFactory.configure(Consumer) method.

The SqsAsyncClient instance to be used by the containers created by this factory can be set using either the setSqsAsyncClient(software.amazon.awssdk.services.sqs.SqsAsyncClient) or setSqsAsyncClientSupplier(java.util.function.Supplier<software.amazon.awssdk.services.sqs.SqsAsyncClient>) methods, or their builder counterparts. The former will result in the containers sharing the supplied instance, where the later will result in a different instance being used by each container.

The factory also accepts the following components:

The non-async components will be adapted to their async counterparts. When using Spring Boot and auto-configuration, beans implementing these interfaces will be set to the default factory.

Example using the builder:

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

 

Example using the default constructor:

 
 @Bean
 SqsMessageListenerContainerFactory defaultSqsListenerContainerFactory(SqsAsyncClient sqsAsyncClient) {
     SqsMessageListenerContainerFactory factory = new SqsMessageListenerContainerFactory<>();
     factory.setSqsAsyncClient(sqsAsyncClient);
     factory.configure(options -> options
             .messagesPerPoll(5)
             .pollTimeout(Duration.ofSeconds(10)));
     return factory;
 }
 
 
 

Example creating a container manually:

 
 @Bean
 SqsMessageListenerContainer defaultSqsListenerContainerFactory(SqsAsyncClient sqsAsyncClient) {
     return SqsMessageListenerContainerFactory
             .builder()
             .configure(options -> options
                     .messagesPerPoll(5)
                     .pollTimeout(Duration.ofSeconds(10)))
             .sqsAsyncClient(sqsAsyncClient)
             .build()
             .create("myQueue");
 }
 
 
Since:
3.0
Author:
Tomaz Fernandes
See Also: