Service Broker Queue Monitor

My previous post shows how to configure an Event Notification to fire whenever a login event occurs. The post uses Service Broker to receive those Event Notifications into a queue, which is then processed by a stored procedure and saved into a standard SQL Server database. This post provides a quick+dirty VB.Net command line monitor that shows how full a Service Broker queue is.

Not service broker queue monitor related, but still pretty nice!  The Quilting Fabric - 1813 by John Lewis Krimmel

The Quilting Fabric – 1813 – John Lewis Krimmel

The following code should be pasted into a blank Visual Studio VB.Net console project. It is trivially easy to translate this into C#, but I like VB – what can I say.

Output looks like this:

ServiceBrokerQueueMonitor 2020.1.31.1340 (c) 2020 Hannah Vernon

Server:     MY\SERVER
Database:   login_auditing
Queue Name: login_audit_queue

Hit Q to quit.

Enter Login:
blah
Enter Password:
Server Date Time    Waiting Messages (x10)
==================  ==========================
Server Date Time    Waiting Messages (x100)
==================  ==========================
Server Date Time    Waiting Messages (x1000)
==================  ==========================
2020-01-31 02:02:54 *************************
2020-01-31 02:03:09 ***********************
2020-01-31 02:03:24 **********************
2020-01-31 02:03:40 *********************
2020-01-31 02:03:55 ********************
2020-01-31 02:04:10 ******************
2020-01-31 02:04:25 *****************
2020-01-31 02:04:41 ***************
2020-01-31 02:04:56 *************
2020-01-31 02:05:11 ************
2020-01-31 02:05:26 ***********
2020-01-31 02:05:41 *********
2020-01-31 02:05:56 ********
2020-01-31 02:06:12 ******
2020-01-31 02:06:27 ***
2020-01-31 02:06:42 *
2020-01-31 02:06:57
2020-01-31 02:07:12
2020-01-31 02:07:27
2020-01-31 02:07:42
2020-01-31 02:07:57
2020-01-31 02:08:12
2020-01-31 02:08:27
2020-01-31 02:08:42

The output consists of the datestamp, plus a number of asterisks representing the approximate number of messages waiting in the queue. The number of asterisks is scaled automatically as needed. In the above example each asterisk indicates 1,000 messages are waiting. The output above is from a very busy SharePoint server, where the maximum number of messages waiting in the queue was around 25,000!

Let me know if you find this Service Broker Queue Monitor helpful. If you have a question about the code, or a suggestion, please post a comment below!