Package io.awspring.cloud.sqs.operations
Class AbstractMessagingTemplate<S>
java.lang.Object
io.awspring.cloud.sqs.operations.AbstractMessagingTemplate<S>
- Type Parameters:
S
- the source message type for conversion
- All Implemented Interfaces:
AsyncMessagingOperations
,MessagingOperations
- Direct Known Subclasses:
SqsTemplate
public abstract class AbstractMessagingTemplate<S>
extends Object
implements MessagingOperations, AsyncMessagingOperations
Base class for
MessagingOperations
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Base class for template options, to be extended by subclasses. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractMessagingTemplate
(MessagingMessageConverter<S> messageConverter, AbstractMessagingTemplate.AbstractMessagingTemplateOptions<?> options) -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> Message<T>
addAdditionalHeaders
(Message<T> message, Map<String, Object> additionalHeaders) protected Collection<Message<Object>>
addTypeToMessages
(Collection<Message<?>> messages) castFromCollection
(Collection<Message<?>> msgs) castFromOptional
(Optional<Message<?>> optional) protected abstract CompletableFuture<Void>
doAcknowledgeMessages
(String endpointName, Collection<Message<?>> messages) protected abstract CompletableFuture<Collection<S>>
doReceiveAsync
(String endpointName, Duration pollTimeout, Integer maxNumberOfMessages, Map<String, Object> additionalHeaders) protected abstract <T> CompletableFuture<SendResult<T>>
doSendAsync
(String endpointName, S message, Message<T> originalMessage) protected abstract <T> CompletableFuture<SendResult.Batch<T>>
doSendBatchAsync
(String endpointName, Collection<S> messages, Collection<Message<T>> originalMessages) protected <T> MessageConversionContext
getReceiveMessageConversionContext
(String endpointName, Class<T> payloadClass) protected <T> MessageConversionContext
getSendMessageConversionContext
(Message<T> message) handleAdditionalHeaders
(Map<String, Object> additionalHeaders) preProcessHeadersForReceive
(String endpointToUse, Map<String, Object> additionalHeaders) protected abstract <T> Message<T>
preProcessMessageForSend
(String endpointToUse, Message<T> message) protected abstract <T> Collection<Message<T>>
preProcessMessagesForSend
(String endpointToUse, Collection<Message<T>> messages) receive()
Receive a message from the default queue with default settings.Receive a message from the provided queue and convert the payload to the provided class.Receive a message from the default queue with default settings.protected CompletableFuture<Optional<Message<?>>>
receiveAsync
(String endpoint, Class<?> payloadClass, Duration pollTimeout, Map<String, Object> additionalHeaders) <T> CompletableFuture<Optional<Message<T>>>
receiveAsync
(String queue, Class<T> payloadClass) Receive a message from the provided queue and convert the payload to the provided class.Collection<Message<?>>
Receive a batch of messages from the default queue with default settings.<T> Collection<Message<T>>
receiveMany
(String queue, Class<T> payloadClass) Receive a batch of messages from the provided queue and convert the payloads to the provided class.Receive a batch of messages from the default queue with default settings.protected CompletableFuture<Collection<Message<?>>>
receiveManyAsync
(String endpoint, Class<?> payloadClass, Duration pollTimeout, Integer maxNumberOfMessages, Map<String, Object> additionalHeaders) <T> CompletableFuture<Collection<Message<T>>>
receiveManyAsync
(String queue, Class<T> payloadClass) Receive a batch of messages from the provided queue and convert the payloads to the provided class.<T> SendResult<T>
Send the provided message along with its headers to the provided queue.<T> SendResult<T>
Send a message to the provided queue with the provided payload.<T> SendResult<T>
send
(T payload) Send aMessage
to the default queue with the provided payload.<T> CompletableFuture<SendResult<T>>
Send the provided message along with its headers to the provided queue.<T> CompletableFuture<SendResult<T>>
Send a message to the provided queue with the provided payload.<T> CompletableFuture<SendResult<T>>
sendAsync
(T payload) Send aMessage
to the default queue with the provided payload.<T> SendResult.Batch<T>
sendMany
(String endpointName, Collection<Message<T>> messages) Send the provided messages along with their headers to the provided queue.<T> CompletableFuture<SendResult.Batch<T>>
sendManyAsync
(String endpointName, Collection<Message<T>> messages) Send the provided messages along with their headers to the provided queue.protected <V> V
unwrapCompletionException
(CompletableFuture<V> future)
-
Constructor Details
-
AbstractMessagingTemplate
protected AbstractMessagingTemplate(MessagingMessageConverter<S> messageConverter, AbstractMessagingTemplate.AbstractMessagingTemplateOptions<?> options)
-
-
Method Details
-
receive
Description copied from interface:MessagingOperations
Receive a message from the default queue with default settings.- Specified by:
receive
in interfaceMessagingOperations
- Returns:
- the message or
Optional.empty()
if none is returned.
-
receive
Description copied from interface:MessagingOperations
Receive a message from the provided queue and convert the payload to the provided class. If no message is returned after the defaultDuration
, anOptional.empty()
is returned.- Specified by:
receive
in interfaceMessagingOperations
- Parameters:
queue
- the queue from which to receive the messages.payloadClass
- the class to which the payload should be converted to.- Returns:
- the message or
Optional.empty()
if none is returned.
-
receiveMany
Description copied from interface:MessagingOperations
Receive a batch of messages from the default queue with default settings.- Specified by:
receiveMany
in interfaceMessagingOperations
- Returns:
- The messages, or an empty collection if none is returned.
-
receiveMany
Description copied from interface:MessagingOperations
Receive a batch of messages from the provided queue and convert the payloads to the provided class. If no message is returned after the defaultDuration
, an empty collection is returned.- Specified by:
receiveMany
in interfaceMessagingOperations
- Parameters:
queue
- the queue from which to receive the messages.payloadClass
- the class to which the payloads should be converted to.- Returns:
- The messages, or an empty collection if none is returned.
-
receiveAsync
Description copied from interface:AsyncMessagingOperations
Receive a message from the default queue with default settings.- Specified by:
receiveAsync
in interfaceAsyncMessagingOperations
- Returns:
- a
CompletableFuture
to be completed with the message, orOptional.empty()
if none is returned.
-
receiveAsync
public <T> CompletableFuture<Optional<Message<T>>> receiveAsync(String queue, Class<T> payloadClass) Description copied from interface:AsyncMessagingOperations
Receive a message from the provided queue and convert the payload to the provided class. If no message is returned after the defaultDuration
, anOptional.empty()
is returned.- Specified by:
receiveAsync
in interfaceAsyncMessagingOperations
- Parameters:
queue
- the queue from which to receive the messages.payloadClass
- the class to which the payload should be converted to.- Returns:
- a
CompletableFuture
to be completed with the message, orOptional.empty()
if none is returned.
-
castFromOptional
-
castFromCollection
-
receiveAsync
-
receiveManyAsync
Description copied from interface:AsyncMessagingOperations
Receive a batch of messages from the default queue with default settings.- Specified by:
receiveManyAsync
in interfaceAsyncMessagingOperations
- Returns:
- a
CompletableFuture
to be completed with the messages, or an empty collection if none is returned.
-
receiveManyAsync
public <T> CompletableFuture<Collection<Message<T>>> receiveManyAsync(String queue, Class<T> payloadClass) Description copied from interface:AsyncMessagingOperations
Receive a batch of messages from the provided queue and convert the payloads to the provided class. If no message is returned after the defaultDuration
, an empty collection is returned.- Specified by:
receiveManyAsync
in interfaceAsyncMessagingOperations
- Parameters:
queue
- the queue from which to receive the messages.payloadClass
- the class to which the payloads should be converted to.- Returns:
- a
CompletableFuture
to be completed with the messages, or an empty collection if none is returned.
-
receiveManyAsync
-
preProcessHeadersForReceive
-
addAdditionalHeaders
-
handleAdditionalHeaders
-
doAcknowledgeMessages
protected abstract CompletableFuture<Void> doAcknowledgeMessages(String endpointName, Collection<Message<?>> messages) -
addTypeToMessages
-
doReceiveAsync
protected abstract CompletableFuture<Collection<S>> doReceiveAsync(String endpointName, Duration pollTimeout, Integer maxNumberOfMessages, Map<String, Object> additionalHeaders) -
send
Description copied from interface:MessagingOperations
Send aMessage
to the default queue with the provided payload. The payload will be serialized if necessary.- Specified by:
send
in interfaceMessagingOperations
- Parameters:
payload
- the payload to send.- Returns:
- The message's
UUID
.
-
send
Description copied from interface:MessagingOperations
Send a message to the provided queue with the provided payload. The payload will be serialized if necessary.- Specified by:
send
in interfaceMessagingOperations
- Parameters:
endpointName
- the queue to send the message to.payload
- the payload to send.- Returns:
- The message's
UUID
.
-
send
Description copied from interface:MessagingOperations
Send the provided message along with its headers to the provided queue. The payload will be serialized if necessary, and headers will be converted to the specific messaging system metadata types.- Specified by:
send
in interfaceMessagingOperations
- Parameters:
endpointName
- the queue to send the message to.message
- the message to be sent.- Returns:
- The message's
UUID
.
-
sendMany
public <T> SendResult.Batch<T> sendMany(@Nullable String endpointName, Collection<Message<T>> messages) Description copied from interface:MessagingOperations
Send the provided messages along with their headers to the provided queue. The payloads will be serialized if necessary, and headers will be converted to the specific messaging system metadata types.- Specified by:
sendMany
in interfaceMessagingOperations
- Parameters:
endpointName
- the queue to send the messages to.messages
- the messages to be sent.- Returns:
- The message's
UUID
.
-
sendAsync
Description copied from interface:AsyncMessagingOperations
Send aMessage
to the default queue with the provided payload. The payload will be serialized if necessary.- Specified by:
sendAsync
in interfaceAsyncMessagingOperations
- Parameters:
payload
- the payload to send.- Returns:
- a
CompletableFuture
to be completed with the message'sUUID
.
-
sendAsync
Description copied from interface:AsyncMessagingOperations
Send a message to the provided queue with the provided payload. The payload will be serialized if necessary.- Specified by:
sendAsync
in interfaceAsyncMessagingOperations
- Parameters:
endpointName
- the queue to send the message to.payload
- the payload to send.- Returns:
- a
CompletableFuture
to be completed with the message'sUUID
.
-
sendAsync
public <T> CompletableFuture<SendResult<T>> sendAsync(@Nullable String endpointName, Message<T> message) Description copied from interface:AsyncMessagingOperations
Send the provided message along with its headers to the provided queue. The payload will be serialized if necessary, and headers will be converted to the specific messaging system metadata types.- Specified by:
sendAsync
in interfaceAsyncMessagingOperations
- Parameters:
endpointName
- the queue to send the message to.message
- the message to be sent.- Returns:
- a
CompletableFuture
to be completed with the message'sUUID
.
-
preProcessMessageForSend
-
sendManyAsync
public <T> CompletableFuture<SendResult.Batch<T>> sendManyAsync(@Nullable String endpointName, Collection<Message<T>> messages) Description copied from interface:AsyncMessagingOperations
Send the provided messages along with their headers to the provided queue. The payloads will be serialized if necessary, and headers will be converted to the specific messaging system metadata types.- Specified by:
sendManyAsync
in interfaceAsyncMessagingOperations
- Parameters:
endpointName
- the queue to send the messages to.messages
- the messages to be sent.- Returns:
- a
CompletableFuture
to be completed with the message'sUUID
.
-
preProcessMessagesForSend
protected abstract <T> Collection<Message<T>> preProcessMessagesForSend(String endpointToUse, Collection<Message<T>> messages) -
doSendAsync
protected abstract <T> CompletableFuture<SendResult<T>> doSendAsync(String endpointName, S message, Message<T> originalMessage) -
doSendBatchAsync
protected abstract <T> CompletableFuture<SendResult.Batch<T>> doSendBatchAsync(String endpointName, Collection<S> messages, Collection<Message<T>> originalMessages) -
getReceiveMessageConversionContext
@Nullable protected <T> MessageConversionContext getReceiveMessageConversionContext(String endpointName, @Nullable Class<T> payloadClass) -
getSendMessageConversionContext
@Nullable protected <T> MessageConversionContext getSendMessageConversionContext(Message<T> message) -
unwrapCompletionException
-