Search code examples
azureazureservicebusazure-sdk-.net

Will Azure Service Bus .net SDK deliver duplicate messages?


I am currently using Azure.Messaging.ServiceBus .net SDK to send high throughput messages in batches to ASB standard. While simulating an intermittent network connectivity situation by turning off the internet during a high throughput batched send, we observed that there were some extra messages delivered to the ASB. The count observed in the ASB portal for the queue didn't match our logs. Can this happen with the ASB? Note that we have enabled retry policies enabled for the client. I came across a similar StackOverflow thread and want to know if there is any latest progress pertaining to this.


Solution

  • Yes; the Service Bus guarantee is at-least-once. Duplicates are possible when publishing fails with an ambiguous state and is retried. Using the duplicate detection feature can help to guard against this, but requires that your application take responsibility for assigning unique MessageId values.

    Duplicates can also occur if a message is received and is not settled. Once its lock has expired, the message is eligible to be received again. Applications receiving messages should ensure that processing is idempotent and any needed detection or guards for duplicates are in place.