1
votes

Is it possible to ensure unique messages on a Azure Service Bus Topic?

I know that ASB has a duplicate detection feature. But that’s not really what I am after.

Let’s say the Topic has a message with MessageID 123. Until this message has been processed by the consumer, I want to discard other message on the Topic with the same id. As soon as this message has been processed, new messages with id 123 are allowed again.

Can the Service Bus help with this, or do we need to handle this in the application layer.

1
You're right, this is not de-duplication feature. It's not a broker feature either. The broker should not be utilized as smart storage.Sean Feldman

1 Answers

0
votes

Well, I wonder why your code would want to send any message with the same ID two times to begin with ? Queue/topic IDs should be unique just like an ID in a database table row should always have unique IDs.

I do not think the Service Bus should do any validation on a message payload, it is not their job. Making sure you do not send two messages with the same ID is a better way to dodge A LOT of further complications. Better to ensure you are not sending two messages with the same ID than manage collisions later ... for example if one of the message inserts data in the database and two entries have the same ID, it will throw an exception.

Also, deleting "other messages" with the same ID will cause unexplained behavior/issues/bugs a lot more than preventing ID collisions ever will. What if your user did something that sent a message with ID 123, expecting to see a result, but his message gets deleted by your system because someone else sent a message with the same ID ? You just broke the system for that user, no ?