Is there a way to set delay seconds while sending messages to SQS.
I am using the below code to send the domain object.
this.queueMessagingTemplate.convertAndSend(queueURL, payload);
Hi @unniksk the interface org.springframework.messaging.core.DestinationResolvingMessageSendingOperations currently does not support sending messages with delayseconds. We might consider adding an additional method to org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate in order to allow setting the delayseconds.
Another option might be a specialized message header, we will discuss internally and come back with an proposal.
I think this one is now fixed at least in 1.1.3
@demboos - can you clarify "fixed"? II'm on 1.2.2 and see nothing in the APIs that indicates delaying individual SQS messages is possible.
You need to use the SqsMessageHeaders.SQS_DELAY_HEADER header.
Here's a simplest way to do it:
sendMessageDelayed( Object payload, String queueName, long delaySeconds) {
Map
new AbstractMap.SimpleEntry<>(MessageHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE),
new AbstractMap.SimpleEntry<>(SqsMessageHeaders.SQS_DELAY_HEADER, (int) delaySeconds))
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
this.queueMessagingTemplate.convertAndSend(queueName,payload, headers);
}
very much obliged @demboos
Thanks @demboos for providing example.
Most helpful comment
You need to use the SqsMessageHeaders.SQS_DELAY_HEADER header.
Here's a simplest way to do it:
sendMessageDelayed( Object payload, String queueName, long delaySeconds) { headers = Stream.of(
Map
new AbstractMap.SimpleEntry<>(MessageHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE),
new AbstractMap.SimpleEntry<>(SqsMessageHeaders.SQS_DELAY_HEADER, (int) delaySeconds))
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));