How could I get the number of unprocessed message count from Azure service bus Queues and based on the count, auto scale the nodes deployed on Azure Kubernetes Services?
I was able to get one of the links which uses Azure Monitor to get the count of messages in the queue and using HPA configuration scale up/down.
Is there any other way we can get the count of messages in the Azure Service Bus queue using Java Code or without using the monitor? Appreciate it if anyone could provide links to read up more on this.
Ideally, monitoring is the best option here if you are using the AKS monitoring or Prometheus for checking the queue size and scaling the number of PODs using the HPA.
Here is one nice example of same scenario with the RabbitMQ queue and using the
Prometheus
with custom metrics. https://ryanbaker.io/2019-10-07-scaling-rabbitmq-on-k8s/However if you looking for a custom solution using Java or any other code you can implement it.
Here is GetMessage counter : https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-counters
The returned MessageCountDetails object has the following properties:
ActiveMessageCount
,DeadLetterMessageCount
,ScheduledMessageCount
,TransferDeadLetterMessageCount
,TransferMessageCount
.Some java sample : https://learn.microsoft.com/en-us/samples/azure/azure-sdk-for-java/servicebus-samples/
This will only give you the count of messages for scaling replicas further you might have to use the
K8s
client library to scale up/down replicas of deployment.