How to ensure message idempotency with multiple competing consumers?

The point of idempotent receiver is that is does not matter if a message is processed several times. Hence, idempotent receivers don't need to somehow detect that a message is a duplicate, they can simply process it as usual ...

So either your receiver is not idempotent, or you are worrying needlessly ...


I've accomplished idempotent messages by ensuring each message has a GUID or other unique identifier and then recording it in the same transaction as which you alter the state in your persistence store.

For each message you can now check if the unique id exists in your persistence store.

If the unique id exists, you know it was processed previously and state changes were persisted in the same transaction.

If the unique id does not exist, you know that it has never been processed.

If two consumers process the same message, because your table where you store your processed unique id's has a unique constraint, when it comes time for both consumers to commit their transactions, one of them must fail and rollback all of it's changes while the other will succeed.