'How To Test for Duplicate Detection with Azure Service Bus

I have enabled duplicate detection with my Azure Service Bus. I have set the Duplicate Detection window to 20secs, see image.

enter image description here

However, when I test with a duplicate message I keep on seeing the message appearing.

Can somene let me know what exactly should happen if I duplicate message is sent?

Updating question to show message_id and Message

enter image description here

I am sending the following message of 20seconds

enter image description here

But it keeps on appearing



Solution 1:[1]

Please be advised that.

Enabling duplicate detection helps keep track of the application-controlled MessageId of all messages sent into a queue or topic during a specified time window. If any new message is sent with MessageId that was logged during the time window, the message is reported as accepted (the send operation succeeds), but the newly sent message is instantly ignored and dropped. No other parts of the message other than the MessageId are considered.

  • When partitioning is enabled, MessageId+PartitionKey is used to determine uniqueness. When sessions are enabled, partition key and session ID must be the same.
  • When partitioning is disabled (default), only MessageId is used to determine uniqueness.

and

Apart from just enabling duplicate detection, you can also configure the size of the duplicate detection history time window during which message-ids are retained. This value defaults to 10 minutes for queues and topics, with a minimum value of 20 seconds to maximum value of 7 days.

See Duplicate detection.

In short: make sure the Message ID properties for the two messages are equal. In the Service Bus Explorer in the portal, click the Expand Advanced Properties link and use the Message ID field there.
If you're using partitioning, fill in the same Partition Key value under the advanced properties, too.

EDIT:
Duplicates are detected within the configured time window. Messages with the same Message ID that have not been sent within the Duplicate Detection time window are not considered duplicates and will be delivered normally.

Enabling duplicate detection and the size of the window directly impact the queue (and topic) throughput, since all recorded message-ids must be matched against the newly submitted message identifier.

This last quote is probably (partially) the reason 7 days is the maximum time window for duplicate detection.

If you absolutely need duplicate detection for a longer period of time, you could think about implementing a Message ID store yourself and check against that when processing messages.
Since chances of an application sending the same message with the same Message ID after more than 7 days are small, I would probably not invest the extra effort.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1