I've a fifo queue, and i'm using org.springframework.cloud.aws.messaging
and here's what i'd like to do:
- Consume the message
- Try to handle it (inner logic)
- If handles fails - write new attribute on the message (without sending the message again to the queue)
I don't want to send the messages to a new queue (i need to keep the order of the messages). also, i don't want to use the deadletter queue for handling errors (same reason as above).
the reason i want to use message attributes is due to the fact that i need to implement in-house retry mechanism, meaning: when consuming the message i'll check the last_try_timestamp and if it's passed my validation then i'll try to handle it, else i'll throw an error.
(I know that the message will continue to be consumed until the MaxRetention
and i'm fine with it)
Is something like that possible?
@SqsListener(value = "#{'${my.queue.fifo}'}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void deadLetterQueueListener(@Headers Map<String, String> headers, String message) throws Exception {
log.info("consuming message");
if(!this.handleMessage(message)){
//Set message attributes (timestamp)
throw new Exception("Failed to handle message");
}
}