I have a scheduled task running on Fargate that publishes thousands of RPC calls through Amazon MQ for workers to consume. Everything was working smoothly for months, but suddenly I began receiving duplicate messages. Each message is sent only once by the scheduler, and the consumers process them without any problems; however, one message is being delivered twice, which is odd. Does anyone have ideas on what might be causing this or how I can debug the issue more effectively?
2 Answers
You might want to design your application to be idempotent. This means that if a message is processed more than once, it won't cause adverse effects, which is a good practice, especially with Amazon MQ.
Keep in mind that Amazon MQ uses an at-least-once delivery mechanism by default. If messages are being sent twice, that can happen under certain conditions. You might consider switching to an exactly-once delivery setup, but there are still some challenges with it. Usually, with at-least-once delivery, you shouldn't see duplicates, but it can occur occasionally.

Switching to exactly-once delivery sounds like a valid option. It’s better for messages to not arrive at all than to deal with duplicates. I checked the documentation but got a bit muddled on how to set up exactly-once for RabbitMQ. Can you explain it?