I am trying to move the message to dead letter queue in AWS if there is an exception while handling the message.
Now I am deleting the original message and sending it to DLQ explicitly. However, while doing this I am losing the message meta information like Original message-id, Total receive count, first sent time stamp etc.
Below is the code snippet for the same.
@Inject
@Named("demo-queue")
private SimpleQueueService sqsService;
@Inject
@Named("dlq")
private SimpleQueueService dlqService;
.
.
.
List<Message> messages = sqsService.receiveMessages(10, 30, 20);
messages.forEach(
m -> dlqService.sendMessage(m.getBody(),
attr -> {
new SendMessageRequest()
.withMessageAttributes(m.getMessageAttributes())
.withMessageBody(m.getBody());
})
);
messages.forEach(message -> sqsService.deleteMessage(message.getReceiptHandle()));
After reaching max receive count when AWS moves the message from the original queue to DLQ it preserves all mentioned attributes. Is there any way we can achieve the same using aws-sdk?
I am using the Agorapulse library with Micronaut to send/receive messages from SQS.