I know it is possible to assign a priority to messages but this is not what I am looking for, I need to assign a priority to subscribers.
For example, 2 services (A and B) are subscribed on the same queue but I would like to have 1 subscriber (A) at higher priority. This means that service A would process all messages that enter the queue when the 2 services are available, and only when service A is busy then service B would process new messages.
Is that possible using .NET and Azure Service Bus?
More details:
Each message takes a good amount of time to process (30-60 seconds) so a service is considered busy as soon as it is processing a single message and each service has a single processor.
One subscriber (A) is enough when the message flow is really low (less than 1 message per minute) but when the flow increases, more services (B, C, etc.) will be booted up to satisfy the demand.
I would like to always prioritize service A so it is 100% busy, then use service B if 1 is not enough, then use C if 2 are not enough, etc.
As the demand lowers, I would like to stop the services in the reverse order (C first, then B). For that, subscribers priority is needed, so that C stops receiving messages when 2 services is enough for the current load.
Edit
Thanks to the current answer, I found out more about Azure Autoscale and the usage of terminate notifications: https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-terminate-notification
This is all great, interesting and of consideration, but I would still like to know the answer to my original question:
Is it possible to assign a priority on a subscriber, when subscribing to an Azure Service Bus Queue?
2
Answers
Why not have 2 queues (A & B) and one service. The service reads each message from queue A until it is empty, then it reads a single message from queue B. Then go back to checking queue A again. Repeat.
This means that anything in queue A is given priority. If something from queue B is being processed, it will complete, but then the higher priority queue will be checked again, before processing another, low priority message.
You do not specify what you mean by the term “service”, but one way to achieve a scalable yet affordable implementation of multiple consuming apps from a queue is to host them in function apps on an app service plan and add a scale out rule based on the queue length to the plan. This is described here https://learn.microsoft.com/en-us/azure/azure-monitor/autoscale/autoscale-get-started