0
votes

I have Azure Service Bus setup with a bunch of queues on it. Some are partitioned. When I tried to read dead letter messages from one of those queues I've deferred messages, then did some massaging and then try to complete those deferred messages. And this is where trouble came in. On the call to the QueueClient.ReceiveBatch() I'm getting InavlidOperationExceptionexception with following message:

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

Inner exception contains following justification:

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

Here is actual line of code, which produces the error:

var deferredMessages = queueClient?.ReceiveBatch(lstSequenceNums);

where lstSequenceNums is type of List<long>and contains sequence numbers of deferred messages; queueClient is of type QueueClient

So I wonder how should this situation be handled? I don't quite understand why that exception has been thrown in the first place? If that expected behavior how I could figure out relation between partition and Service Bus message sequence number?

Any help would be greatly appreciated.

2

2 Answers

1
votes

From Azure Service Bus partitioning documentation, for a single message requested

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.

and

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.

I suspect you ask for messages from multiple partitions by requesting a batch using Sequence numbers from different partitions, it would force to query too many brokers and Azure Service Bus service doesn't allow that.

SequenceNumber can help to determine what partition your messages are coming from. Top 16 bits are used to encode the partition ID. You could you that to break your batch into separate calls.

ReceiveBatch(IEnumerable<int64>) does say anything about this. I suggest to raise an issue with the team to clarify the documentation.

0
votes

I made it work by reading messages one by one(getting all messages in the loop) and abandoning batch reading approach completely, because it's too fragile and issues-pron. It's the only option one have at the moment, imho, if there are partitioned queues on one's Azure Service Bus. Sean Feldman provided some insights(thank you again), but it doesn't provide any acceptable way of making ReceiveBatch viable solution for the task at hand.