I have a javascript logging utility that sends requests in bulk to my server which then relays them to a Queue Client ( Microsoft.ServiceBus.Messaging.QueueClient
). I want to send them in batch asynchronously to the ServiceBus and still have them processed in the order they are placed into the batch I am sending. The documentation for SendBatchAsync
shows that the method is for "batch" processing. This makes me think I can send it a batch of requests and have them processed as a single unit (ie: sequentially). Although, it appears that the messages are getting processed out of order. I'm using OnMessage
to receive the messages; I'm not sure if this is a limitation or what am I missing?
I get that async doesn't guarantee order vs. other async requests, but this is a single request. I don't want to have to wait for a response before responding to the javascript client as I'm just trying to send them off, but I still need to ensure they stay in order since they are sequential events.
Here is how I send them to the queue:
MyQueueClient.SendBatchAsync(MyListOfBrokerMessages);
Then I process them:
ServiceBus.TrackerClient.OnMessage((m) =>
{
try
{
ProcessMessage(m);
}
I don't get the point of the batch processing if it doesn't process as a batch other than maybe making a single request. There must be some way to send a batch and have it process in order??
EDIT: I've tried using Send
instead of SendBatchAsync
and I've set MaxConcurrentCalls
to 1 and yet the messages are still not in order.
Taken from MSDN:
SessionId: If a message has the
Microsoft.ServiceBus.Messaging.BrokeredMessage.SessionId
property set, then Service Bus uses theSessionId
property as the partition key. This way, all messages that belong to the same session are handled by the same message broker. This enables Service Bus to guarantee message ordering as well as the consistency of session states.
For a coding sample employing SessionId
and AcceptSessionReceiver
see.
What you can do is to use Sessions here,
sessions id
to all the messages in the batch AcceptMessageSession()
will give you a session ReceiveBatch
). This session will give you all the messages in that batch alone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.