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- Since:
- 3.0
- Author:
- Tomaz Fernandes
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classBase class for template options, to be extended by subclasses. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractMessagingTemplate(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> MessageConversionContextgetReceiveMessageConversionContext(String endpointName, Class<T> payloadClass) protected <T> MessageConversionContextgetSendMessageConversionContext(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 <T> CompletableFuture<Message<T>>preProcessMessageForSendAsync(String endpointToUse, Message<T> message) protected abstract <T> Collection<Message<T>>preProcessMessagesForSend(String endpointToUse, Collection<Message<T>> messages) protected <T> CompletableFuture<Collection<Message<T>>>preProcessMessagesForSendAsync(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 aMessageto 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 aMessageto 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> VunwrapCompletionException(CompletableFuture<V> future)
-
Constructor Details
-
AbstractMessagingTemplate
protected AbstractMessagingTemplate(MessagingMessageConverter<S> messageConverter, AbstractMessagingTemplate.AbstractMessagingTemplateOptions<?> options)
-
-
Method Details
-
receive
Description copied from interface:MessagingOperationsReceive a message from the default queue with default settings.- Specified by:
receivein interfaceMessagingOperations- Returns:
- the message or
Optional.empty()if none is returned.
-
receive
Description copied from interface:MessagingOperationsReceive 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:
receivein 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:MessagingOperationsReceive a batch of messages from the default queue with default settings.- Specified by:
receiveManyin interfaceMessagingOperations- Returns:
- The messages, or an empty collection if none is returned.
-
receiveMany
Description copied from interface:MessagingOperationsReceive 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:
receiveManyin 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:AsyncMessagingOperationsReceive a message from the default queue with default settings.- Specified by:
receiveAsyncin interfaceAsyncMessagingOperations- Returns:
- a
CompletableFutureto 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:AsyncMessagingOperationsReceive 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:
receiveAsyncin interfaceAsyncMessagingOperations- Parameters:
queue- the queue from which to receive the messages.payloadClass- the class to which the payload should be converted to.- Returns:
- a
CompletableFutureto be completed with the message, orOptional.empty()if none is returned.
-
castFromOptional
-
castFromCollection
-
receiveAsync
-
receiveManyAsync
Description copied from interface:AsyncMessagingOperationsReceive a batch of messages from the default queue with default settings.- Specified by:
receiveManyAsyncin interfaceAsyncMessagingOperations- Returns:
- a
CompletableFutureto 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:AsyncMessagingOperationsReceive 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:
receiveManyAsyncin interfaceAsyncMessagingOperations- Parameters:
queue- the queue from which to receive the messages.payloadClass- the class to which the payloads should be converted to.- Returns:
- a
CompletableFutureto 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:MessagingOperationsSend aMessageto the default queue with the provided payload. The payload will be serialized if necessary.- Specified by:
sendin interfaceMessagingOperations- Parameters:
payload- the payload to send.- Returns:
- The message's
UUID.
-
send
Description copied from interface:MessagingOperationsSend a message to the provided queue with the provided payload. The payload will be serialized if necessary.- Specified by:
sendin 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:MessagingOperationsSend 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:
sendin 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:MessagingOperationsSend 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:
sendManyin 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:AsyncMessagingOperationsSend aMessageto the default queue with the provided payload. The payload will be serialized if necessary.- Specified by:
sendAsyncin interfaceAsyncMessagingOperations- Parameters:
payload- the payload to send.- Returns:
- a
CompletableFutureto be completed with the message'sUUID.
-
sendAsync
Description copied from interface:AsyncMessagingOperationsSend a message to the provided queue with the provided payload. The payload will be serialized if necessary.- Specified by:
sendAsyncin interfaceAsyncMessagingOperations- Parameters:
endpointName- the queue to send the message to.payload- the payload to send.- Returns:
- a
CompletableFutureto be completed with the message'sUUID.
-
sendAsync
public <T> CompletableFuture<SendResult<T>> sendAsync(@Nullable String endpointName, Message<T> message) Description copied from interface:AsyncMessagingOperationsSend 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:
sendAsyncin interfaceAsyncMessagingOperations- Parameters:
endpointName- the queue to send the message to.message- the message to be sent.- Returns:
- a
CompletableFutureto be completed with the message'sUUID.
-
preProcessMessageForSend
-
preProcessMessageForSendAsync
protected <T> CompletableFuture<Message<T>> preProcessMessageForSendAsync(String endpointToUse, Message<T> message) -
sendManyAsync
public <T> CompletableFuture<SendResult.Batch<T>> sendManyAsync(@Nullable String endpointName, Collection<Message<T>> messages) Description copied from interface:AsyncMessagingOperationsSend 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:
sendManyAsyncin interfaceAsyncMessagingOperations- Parameters:
endpointName- the queue to send the messages to.messages- the messages to be sent.- Returns:
- a
CompletableFutureto be completed with the message'sUUID.
-
preProcessMessagesForSend
protected abstract <T> Collection<Message<T>> preProcessMessagesForSend(String endpointToUse, Collection<Message<T>> messages) -
preProcessMessagesForSendAsync
protected <T> CompletableFuture<Collection<Message<T>>> preProcessMessagesForSendAsync(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
-