MSMQ Heartbeat checks with QueueMonitor

Here’s how wikipedia describes heartbeats in computing:

In computer science, a heartbeat is a periodic signal generated by hardware or software to indicate normal operation or to synchronize other parts of a computer system.

How can we apply heartbeats to MSMQ?

We can start with simple heartbeat checks – QueueMonitor sends message to a queue, and tries to receive it from that same queue. If message arrives within specified timeout, everything is OK, MSMQ is fully working and messages can be both sent and received. Otherwise, we raise alarm and someone should check what’s wrong.

Why is this better than just checking Message Queueing service?

Sometimes service is running, but actual MSMQ queues are not – we used all free space on disk, remote machine can’t be reached, queues are filled up, there’s some internal MSMQ problem, permissions are mixed up, whatever. However if we can successfully send and receive message, we know that basic MSMQ functionality 100% works.

That’s all fine, but why not include user’s application in this check too?

Let’s assume that application already receives messages from some queue. If QueueMonitor sends heartbeat messages to that queue, and application resends heartbeats¬†to another queue, we can receive them from that second queue.

If heartbeat arrives within specified timeout, we’ll know that BOTH user’s application and MSMQ work OK. Small drawback is that we have to modify application as well to recognize heartbeat messages and sends them to some queue. This type of check is called “advanced” heartbeat check in QueueMonitor.

In order to minimize changes to outside application, QueueMonitor has configurable message label and body – they could contain anything, as long they also contain heartbeat token somewhere. This token is just a small piece of text containing timestamp:

Heartbeat:’1760848984445′

In order to put this in message, you should use {heartbeat_token} macro, which QueueMonitor replaces with current timestamp when sending heartbeat.

Just create new Heartbeat task from QueueMonitor 1.6+ and your MSMQ monitoring will be greatly improved.