0

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.

fatherOfWine
  • 1,191
  • 16
  • 39

2 Answers2

1

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.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • 1
    @SuanFeldman Thank you for you answer. What you are saying is conforming my suspicions. Though it renders ReceiveBatch practically unusable. Why should one be concerned partitioned queue or not? I still fail to understand how behavior of the aforementioned method could be considered acceptable, but it is what it is. I made it work by reading messages one by one. – fatherOfWine Oct 11 '17 at 15:37
  • @fatherOfWine no problem at all. I do recommend raising an issue with the ASB team. Clarification would be nice. Also, I've noticed `ReceiveBatch(IEnumerable)` is no longer available with the new .NET Standard client. Which might be an indication on the future of this API. – Sean Feldman Oct 11 '17 at 17:55
  • Wow!This functionality is going away!?! Thanks for heads up! So mush for my efforts to figure out how to use those batch-ended methods!:)) – fatherOfWine Oct 11 '17 at 18:23
  • My bad, it's [still there](https://github.com/Azure/azure-service-bus-dotnet/blob/43723e2addb9313592b83fceb84595b4be5e5c33/src/Microsoft.Azure.ServiceBus/Core/MessageReceiver.cs#L352). Just with a better name :) I'm sure you'd hit the same issue as it's a broker side concern. And if so, documentation must be provided. – Sean Feldman Oct 11 '17 at 19:29
0

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.

fatherOfWine
  • 1,191
  • 16
  • 39