如何使用 Azure 服务总线测试重复检测

How To Test for Duplicate Detection with Azure Service Bus

我已使用 Azure 服务总线启用重复检测。我已将重复检测 window 设置为 20 秒,请参见图片。

但是,当我使用重复消息进行测试时,我一直看到该消息出现。

有人可以告诉我如果我发送了重复的消息到底会发生什么吗?

正在更新问题以显示 message_id 和消息

我正在发送以下 20 秒的消息

但它不断出现

请注意。

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.

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.

Duplicate detection

简而言之:确保两条消息的 Message ID 属性相等。在门户的服务总线资源管理器中,单击 展开高级属性 link 并使用那里的 Message ID 字段。
如果您正在使用分区,请在高级属性下也填写相同的分区键值。

编辑:
在配置的时间内检测到重复项 window。具有相同消息 ID 且未在重复检测时间内发送的消息 window 不被视为重复消息,将正常传送。

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.

这最后一句话可能(部分)是 7 天是重复检测的最长时间 window 的原因。

如果您绝对需要较长时间的重复检测,您可以考虑自己实现一个消息 ID 存储,并在处理消息时进行检查。
由于应用程序在超过 7 天后发送具有相同消息 ID 的相同消息的可能性很小,我可能不会投入额外的精力。