Class SqsMessageListenerContainerFactory<T>
- Type Parameters:
T- theMessagepayload 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,Objectcan 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:
MessageInterceptorMessageListenerErrorHandlerAsyncMessageInterceptorAsyncMessageListenerAsyncErrorHandler
Example using the builder:
@Bean
SqsMessageListenerContainerFactory
Example using the default constructor:
@Bean
SqsMessageListenerContainerFactory
Example creating a container manually:
@Bean
SqsMessageListenerContainer defaultSqsListenerContainerFactory(SqsAsyncClient sqsAsyncClient) {
return SqsMessageListenerContainerFactory
.builder()
.configure(options -> options
.maxMessagesPerPoll(5)
.pollTimeout(Duration.ofSeconds(10)))
.sqsAsyncClient(sqsAsyncClient)
.build()
.createContainer("myQueue");
}
- Since:
- 3.0
- Author:
- Tomaz Fernandes, Joao Calassio
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SqsMessageListenerContainerFactory.Builder<T>builder()protected voidconfigureContainerOptions(Endpoint endpoint, SqsContainerOptionsBuilder options) protected SqsMessageListenerContainer<T>createContainerInstance(Endpoint endpoint, SqsContainerOptions containerOptions) protected software.amazon.awssdk.services.sqs.SqsAsyncClientvoidsetSqsAsyncClient(software.amazon.awssdk.services.sqs.SqsAsyncClient sqsAsyncClient) Set theSqsAsyncClientinstance to be shared by the containers.voidsetSqsAsyncClientSupplier(Supplier<software.amazon.awssdk.services.sqs.SqsAsyncClient> sqsAsyncClientSupplier) Set a supplier forSqsAsyncClientinstances.Methods inherited from class io.awspring.cloud.sqs.config.AbstractMessageListenerContainerFactory
addMessageInterceptor, addMessageInterceptor, configure, configureAbstractContainer, configureContainer, createContainer, createContainer, setAcknowledgementResultCallback, setAcknowledgementResultCallback, setAsyncMessageListener, setContainerComponentFactories, setErrorHandler, setErrorHandler, setMessageListener
-
Constructor Details
-
SqsMessageListenerContainerFactory
public SqsMessageListenerContainerFactory()
-
-
Method Details
-
createContainerInstance
protected SqsMessageListenerContainer<T> createContainerInstance(Endpoint endpoint, SqsContainerOptions containerOptions) -
getSqsAsyncClientInstance
protected software.amazon.awssdk.services.sqs.SqsAsyncClient getSqsAsyncClientInstance() -
configureContainerOptions
-
setSqsAsyncClientSupplier
public void setSqsAsyncClientSupplier(Supplier<software.amazon.awssdk.services.sqs.SqsAsyncClient> sqsAsyncClientSupplier) Set a supplier forSqsAsyncClientinstances. A new instance will be used for each container created by this factory. Useful for high throughput containers where sharing anSqsAsyncClientwould be detrimental to performance.- Parameters:
sqsAsyncClientSupplier- the supplier.
-
setSqsAsyncClient
public void setSqsAsyncClient(software.amazon.awssdk.services.sqs.SqsAsyncClient sqsAsyncClient) Set theSqsAsyncClientinstance to be shared by the containers. For high throughput scenarios the client should be tuned for allowing higher maximum connections.- Parameters:
sqsAsyncClient- the client instance.
-
builder
-