Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing the Priority Queue pattern in Azure Service Bus

We're using Azure Service Bus in order to send messages between different applications in our company, and sync data

We often run batches, upwards of tens of thousands of records, and we're having an issue when we try to send an additional message during the running of a batch. Basically the message has to wait until the entire batch in front of it finishes.

We'd like to be able to set the priorities on messages, so that messages that come from one application would get processed before messages that we send in bulk, even if there are already 10,000+ messages in the service bus topic.

I found some information about this from Microsoft, which looks to be exactly what we want to do: https://learn.microsoft.com/en-us/azure/architecture/patterns/priority-queue

enter image description here

But I can't find any information about how to implement this with Azure Service Bus, and I don't see any settings on the topic in the Azure portal that would allow this

And using the Service Bus Explorer, there doesn't seem to be any Priority setting on the messages.

enter image description here

Is this possible with Azure Service Bus?

like image 657
Steven Avatar asked Oct 30 '25 10:10

Steven


1 Answers

Natively Azure Service Bus does not have the concept of message priority. What that means is that when all messages sent to Azure Service Bus will have the same priority and the messages will be processed in the order they were received.

Solution proposed in the link you included involves writing different messages to different queues (high, medium and low priority queues)

enter image description here

Other alternative is to make use of Azure Service Bus Topics and Subscriptions as mentioned here: https://learn.microsoft.com/en-us/azure/architecture/patterns/priority-queue#example

The way it would work is that you would create 3 Subscriptions (let's call them high, medium and low priority subscription) and you will set the routing rules so that if a message is marked as high priority item, it will be automatically routed to high priority subscription.

All you will need to do is set the priority on the message (by setting a custom property) and then specify filtering rules on each Subscription so that messages are filtered and delivered to appropriate Subscriptions.

enter image description here

like image 132
Gaurav Mantri Avatar answered Nov 01 '25 06:11

Gaurav Mantri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!