Monitor azure service bus queue length - azure

Team,
I would like to monitor a azure service bus dead letter queue length using normal C#. it should throw an exception when the receiver is not able/late to process messages from the active queue and due to time delay the count in the dead letter queue increases.
Is there a way without using ApplicationInsights ?

While using the full framework .NET client still provides message counts, according to the Azure Service Bus team the advised way is to use Azure Monitor service. The service has a .NET client that can be used to obtain the needed information (example). Service Bus team has also published a sample here. The client has not provided all the information in the past, but that is work in progress and could be different now than before.
In case you're still planning to use Service Bus client to retrieve message counts, I highly advise to use .NET Standard client rather than full framework client. The "new" client doesn't have NamespaceManager, but it has an equivalent, ManagementClient that will provide the functionality you're looking for, including improvements over its predecessor and bug fixes moving forward. The "old" client is on a limited support only.

If you are using the "old" Service Bus SDK, you can get it from MessageCountDetails:
var msg = NamespaceManager.CreateFromConnectionString(connectionString);
var queue = msg.GetQueue(queueName);
var dlqCount = queue.MessageCountDetails.DeadLetterMessageCount;

It is possible to fetch the Count of Messages(both active and dead-letter) in a Queue with the help of the latest Azure Monitor Metrics. Or you can make use of the Azure Monitor in Azure portal, which allows you to configure dashboards and alerts.

Related

Application Insights - Application Map of Function reading from service bus queue

I'm playing around with the Application Map feature of Application Insights and I'm struggling to generate what I expected to see.
I have a "Sender" (HTTP Trigger Azure Function) that writes to a Service Bus Queue via a binding, and a "Receiver" (Service Bus Trigger Azure Function) that reads from the same queue.
I was expecting to see an Application Map that is something like:
Sender -> Service Bus -> Receiver
But I'm struggling. The sending bit seems to work out of the box, as I get:
Image showing Sender -> Service Bus
Unfortunately I'm unable to generate an arrow that leaves the Service Bus. I've tried putting the receiver in a separate project to the sender, as well as the receiver using a separate App Insights resource. This latter attempt just gave me two different app insights to read and all I can see if the function being executed.
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-end-to-end-tracing?tabs=net-standard-sdk-2#trace-message-processing suggests it's possible in normal .NET code. But I can't find an equivalent resource for functions.
Is what I'm expecting possible?
Does this work if you disable the preview mode in Application Map? If so, it might be because you need to send more than just 1 call at a time. The preview mode requires that you send data for more than 1 minute on a new Application Insights resource. I tried an out-of-the-box solution using C# Script and it looks like correlation should work at least with Service Bus extension version: Microsoft.Azure.WebJobs.Extensions.ServiceBus 4.2.1 (from the default Functions 2.0 extension bundle).
Distributed tracing of Azure ServiceBus was only release in version v2.21 - you can see the information in the release notes for beta 2
Added support for distributed tracing with Azure.Messaging.ServiceBus
Sorry for all the links, but doesn't make much sense without them.

Azure Service Bus queues

I'm new to azure cloud and my assignments requires me to implement service bus queues.
Question: Implement the Service Bus queues in your application. By using the queues and Service Bus, you will be able to manage the communication between the N-tier applications in Azure.
I have made a library management system using .net C# and not in MVC. and deployed it in the cloud. I don't know how to implement it.
Do i need to make new project for service bus or can i implement it on the existing system.
I have made a form page with Fullname, Email, Subject and Message Box. there is submit Button and onclick event can i implement service bus queue? help please. Thank you for time. Sorry for asking question in unclear manner. New to stackoverflow.
I believe you have already create the service bus queue, still you may check https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-portal for your reference.
Then, you need to leverage the nuget pacakges in your project so that you can send messages to and receive messages from a Service Bus queue :
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues
For more related details : https://github.com/toddkitta/azure-content/blob/master/articles/service-bus/service-bus-dotnet-how-to-use-queues.md
https://www.c-sharpcorner.com/article/azure-service-bus-queues/
https://www.c-sharpcorner.com/article/azure-service-bus-and-queue-implementation-using-c-sharp-small-intro-and-sample-app/
https://azuresdkdocs.blob.core.windows.net/$web/dotnet/Azure.Messaging.ServiceBus/7.0.0-preview.1/api/index.html

Determining how many messages are on the Azure Service Bus Queue for a specific SessionId

I have a servicebus queue that contains messages with different session ids.
Is there a way to get the message count for a specific session id?
You can retrieve the count of messages held in queues and subscriptions by using Azure Resource Manager and the Service Bus NamespaceManager APIs in the .NET Framework SDK as described here.
You can also refer the suggestions provided by the community members here. See if this helps you.

Azure Service Bus, check if ASB is throttled by using SDK

We use Azure Service Bus to send messages from one service to another. Producer produces quite huge amount of messages(a couple of millions) during 1-2 hours. As a result our Service Bus(we use Premium Azure Service Bus) is throttled and we receive errors on producer and consumer sides. I wonder if we could check somehow the load of our ASB by using Azure SDK(we use ASB Java SDK) and if it is high we can slow down the services that sends messages into the queue/topic.
I also understand that we can add more Premium units, but it is the last option we will take.
What we use:
Azure Service Bus Java SDK
Java 9 and Spring Boot 2.0
Azure Service Bus Premium version
Do you have any recommendations for my case? Any recommendation - patterns, frameworks, ASB SDK features would be great.
What you usually can do is to check from the portal your usage (from the overview panel), there is no feature in the SDK itself that can show you the load on your service bus namespace.
Since you're using premium messaging, there is no certain threshold that can determine if you've exceeded your messaging unit capacity or not.
you will get throttling errors as shown in the documentation:
Also be aware that you can scale up and down according to your usage with how many messaging units you want.

Reading Azure Service Bus Queue

I'm simply trying to work out how best to retrieve messages as quickly as possible from an Azure Service Bus Queue.
I was shocked that there wasn't some way to properly subscribe to the queue for notifications and that I'm going to have to poll. (unless I'm wrong in which case the documentation is terrible).
I got long polling working, but checking a single message every 60 seconds looks like it'll cost around £900 per month (again, unless I've misunderstood that). And if I add a redundant/second service to poll it'll double.
So I'm wondering what the best/most cost efficient way of doing it is.
Essentially I just want to take a message from the queue, perform an API lookup on some internally held data (perhaps using hybrid services?) and then perhaps post a message back to a different queue with some additional information .
I looked at worker roles(?) -- is that something that could do it?
I should mention that I've been looking at doing this with node.js.
Check out these videos from Scott Hanselman and Mark Simms on Azure Queues.
It's C# but you get the idea.
https://channel9.msdn.com/Search?term=azure%20queues%20simms#ch9Search
Touches on:
Storage Queues vs. Service Bus Queues
Grabbing messages in bulk vs. one by one (chunky vs. chatty)
Dealing with poison messages (bad actors)
Misc implementation details
Much more stuff i can't remember now
As for your compute, you can either do a VM, a Worker Role (Cloud Services), App Service Webjobs, or Azure Functions.
The Webjobs SDK and Azure Functions bot have a way to subscribe to Queue events (notify on message).
(Listed from IaaS to PaaS to FaaS - Azure Functions - if such a thing exists).
Azure Functions already has sample code provided as templates to do all that with Node. Just make a new Function and follow the wizard.
If you need to touch data on-prem you either need to look at integrating with a VNET that has site-to-site connectivity back to your prem, or Hybrid Connections (App Service only!). Azure Functions can't do that yet, but every other compute is a go.
https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-get-started/
(That tutorial is Windows only but you can pull data from any OS. The Hybrid Connection Manager has to live on a Windows box, but then it acts as a reverse proxy to any host on your network).
To deal with Azure ServiceBus Queue easily, the best option seems to be Azure Webjob.
There is a ServiceBusTrigger that allows you to get messages from an Azure ServiceBus queue.
For node.js integration, you should have a look at Azure Function. It is built on top of the webjob SDK and have node.js integration :
Azure Functions NodeJS developer reference
Azure Functions Service Bus triggers and bindings for queues and topics
In the second article, there is an example on how get messages from a queue using Azure Function and nodejs :
module.exports = function(context, myQueueItem) {
context.log('Node.js ServiceBus queue trigger function processed message', myQueueItem);
context.done();
};

Resources