Azure 服务总线。队列客户端。 ReceiveBatch 问题

Azure ServiceBus. QueueClient. ReceiveBatch issue

我有 Azure 服务总线设置,上面有一堆队列。有些是分区的。当我尝试从其中一个队列中读取死信消息时,我延迟了消息,然后进行了一些按摩,然后尝试完成这些延迟消息。这就是问题所在。在调用 QueueClient.ReceiveBatch() 时,我收到 InavlidOperationException 异常消息:

ReceiveBatch of sequence numbers from different partitions is not supported for an entity with partitioning enabled.

内部异常包含以下理由:

BR0012ReceiveBatch of sequence numbers from different partitions is not supported for an entity with partitioning enabled.

这是产生错误的实际代码行:

var deferredMessages = queueClient?.ReceiveBatch(lstSequenceNums);

其中 lstSequenceNums 是 List<long> 的类型并且包含延迟消息的序列号; queueClient 的类型为 QueueClient

请问这种情况应该怎么处理?我不太明白为什么首先会抛出该异常?如果出现这种预期行为,我如何找出分区和服务总线消息序列号之间的关系?

如有任何帮助,我们将不胜感激。

来自 Azure 服务总线 partitioning documentation,请求一条消息

When a client wants to receive a message from a partitioned queue, or from a subscription to a partitioned topic, Service Bus queries all fragments for messages, then returns the first message that is obtained from any of the messaging stores to the receiver.

Each partitioned queue or topic consists of multiple fragments. Each fragment is stored in a different messaging store and handled by a different message broker.

怀疑 您通过使用来自不同分区的序列号请求一个批次来请求来自多个分区的消息,这会强制查询太多代理,而 Azure 服务总线服务不会不允许这样。

SequenceNumber 可以 帮助确定您的消息来自哪个分区。前 16 位用于 encode the partition ID。你能不能把你的批处理分成单独的调用。

ReceiveBatch(IEnumerable<int64>) does say anything about this. I suggest to raise an issue 与团队一起澄清文档。

我通过一条一条地读取消息(循环获取所有消息)并完全放弃批量读取方法来实现它,因为它太脆弱且容易出问题。如果一个人的 Azure 服务总线上有分区队列,这是目前唯一的选择,恕我直言。肖恩·费尔德曼 (Sean Feldman) 提供了一些见解(再次感谢您),但它没有提供任何可接受的方法来为手头的任务制定 ReceiveBatch 可行的解决方案。