Class SqsMessageListenerContainerFactory<T>
- Type Parameters:
T
- theMessage
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:
MessageInterceptor
MessageListener
ErrorHandler
AsyncMessageInterceptor
AsyncMessageListener
AsyncErrorHandler
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
.messagesPerPoll(5)
.pollTimeout(Duration.ofSeconds(10)))
.sqsAsyncClient(sqsAsyncClient)
.build()
.create("myQueue");
}
- Since:
- 3.0
- Author:
- Tomaz Fernandes
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SqsMessageListenerContainerFactory.Builder<T>
builder()
protected void
configureContainerOptions
(Endpoint endpoint, SqsContainerOptionsBuilder options) protected SqsMessageListenerContainer<T>
createContainerInstance
(Endpoint endpoint, SqsContainerOptions containerOptions) protected software.amazon.awssdk.services.sqs.SqsAsyncClient
void
setSqsAsyncClient
(software.amazon.awssdk.services.sqs.SqsAsyncClient sqsAsyncClient) Set theSqsAsyncClient
instance to be shared by the containers.void
setSqsAsyncClientSupplier
(Supplier<software.amazon.awssdk.services.sqs.SqsAsyncClient> sqsAsyncClientSupplier) Set a supplier forSqsAsyncClient
instances.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 forSqsAsyncClient
instances. A new instance will be used for each container created by this factory. Useful for high throughput containers where sharing anSqsAsyncClient
would be detrimental to performance.- Parameters:
sqsAsyncClientSupplier
- the supplier.
-
setSqsAsyncClient
public void setSqsAsyncClient(software.amazon.awssdk.services.sqs.SqsAsyncClient sqsAsyncClient) Set theSqsAsyncClient
instance 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
-