MSMQ comes with a series of sample applications and tools, together with the main administrative tool Message Queue Explorer. The samples include an application named Distributed Draw that allows two people to draw on a window and see the other person's drawings at the same time—the drawing instructions are sent from one machine to the other using MSMQ.
We're going to look at a less exciting, but potentially more useful tool in this chapter. Before we do so, however, there's no better way to get familiar with MSMQ than by having a quick play with Message Queue Explorer. This is our first step.
Using MSMQ Explorer
Although it seemed likely that the MSMQ Administrator would become just a snap-in to the Microsoft Management Console (MMC), this hasn’t happened yet. Instead a similar but independent application called Message Queue Explorer is provided. This shows the MSMQ enterprise as a tree in the left-hand pane, and the right-hand pane displays information about the currently selected item in the tree:
Display Columns and Properties
MQ Explorer is more configurable than the MMC. By selecting Columns from the View menu, you can specify the columns that will appear in the right-hand window, and their ordering, for each type of item that you might select in the left-hand window:
By selecting a computer in the left-hand pane and clicking the Properties toolbar button (or right-clicking and selecting Properties from the short-cut menu in the usual way) you get useful information about that computer. Here, we're setting the quota limits, which control the maximum size of all the messages and journals stored on this machine. If the machine is an Independent Client (as ours is here) you can also use this dialog to change the site that it 'belongs' to—the parent site. As we mentioned earlier, you have to do this before moving to a new site if you want to be able to receive messages whilst connected to that site:
Sending Test Messages
The Send Test Messages option on the Tools menu of MQ Explorer can be used to send test messages to confirm that the installation is working properly. This opens a dialog where you can select an existing queue or create a new one:
In our case, we're creating a new queue named test queue on a remote machine named daisy:
Now, clicking the Send button sends one message each time to that queue. You can see that the queue is displayed in MQ Explorer in the next screen shot, and the messages are visible:
We can also use MQ Explorer to view the private queues on the machines, and to create new queues that will accept transactional messages. Recall that transactional messaging requires this special type of queue to be available:
If It Doesn't Seem To Work
Finally, if nothing seems to be working you can use a special form of 'ping' called MQPing to see if remote machines are responding. In the following screen shot you can see from the small arrows added to the computer icons (they're actually green in MSMQ Explorer) that daisy and portia are responding, but dan seems to be asleep. In fact this is because that computer is not currently running.
Using The MQ API Test Sample
While MQ Explorer can create simple test messages, you get more idea of the possibilities by using the MQ API Test tool. This is available from the Start menu, unless you chose not to install the samples during setup. As you can see from the next screenshot, the interface is less than intuitive—with just a series of buttons that allow you to perform the standard actions available in MSMQ. The letters on the buttons stand for, respectively, Create Queue, Delete Queue, Open Queue, Close Queue, Send Message, Retrieve Message, Locate Queue. These options are also available from the Api menu.
Locating And Opening A Queue
Rather than creating a new queue this time, we'll locate an existing one. Here we've clicked the L button to locate the queue named test queue that we created in MQ Explorer in the previous section of this chapter. If you didn’t create this queue you'll need to do so first if you want to follow through this example:
You can see in the main window that MSMQ returned the full path and name of the one matching queue, and that it's not currently open in our application:
Next we open the queue, by clicking the O (Open) button, and specify that we want SEND access, as shown in the previous screen shot.
Sending A Message And Closing the Queue
Providing we get confirmation in the main window that the queue opened successfully, we can send a message. This is done by clicking the S button to open the MQSendMessage dialog:
We've left most of the settings at their defaults, and just entered the Label and Body of the message we want to send. The values -1 for the Time To Reach Queue and Time To Be Received settings indicate that there is no timeout, or expiry, for the message. You'll meet these and the rest of the options later in this chapter, where we'll discuss the possible values and their meanings in more detail. In the main window of the screen shot below, you can see that the message was sent successfully. So now we can close the queue by clicking the Cl (Close) button:
Retrieving A Message
To retrieve the message, we need to open the queue for read access by clicking the O (Open) button again. In the next screen shot you can see that we're selecting the RECEIVE access option this time:
Again, the main window indicates that the queue was opened OK, and so we can click the R (Retrieve) button to receive the topmost message in the queue—the one we just sent. We've left the values for the Timeout (the time to wait for the message to be retrieved before giving up) and the Body Length (the maximum number of characters to retrieve from the message body) set to the MQ API Test application's defaults:
The contents of the received message are displayed in the main window. You can then tidy up by using the Cl button to close the queue again, and the D button to delete it.
Even though we sent and received the message on the same machine, we used a message queue located on another, remote, MSMQ Server—which could easily have been on the other side of the continent (OK, so ours was only on the other side of the office). Of course, we could just as easily have accessed this remote queue from that machine, or any other MSMQ Server within our enterprise.