Recoverable Delivery

Overview

MSMQ provides you with a number of distinct methods for delivering messages. This sample demonstrates how to open a message queue and transmit a simple message using one type of delivery called recoverable delivery. Recoverable delivery means that message delivery is guaranteed, as MSMQ will either forward the message immediately to the queue or save it to disk. If you use recoverable delivery, you can be sure that your message will arrive at its destination, even if the computer crashes or the network is temporarily down. This guarantee is not without a price, however; recoverable delivery is slower than other forms of delivery.

Code Tour

This example first creates an instance of the MSMQQueueInfo object, which will be used as a template for the actual queue object instances. MSMQQueueInfo contains a number of properties that can be used to configure the queue instances it will create, but in this sample, only the PathName property is set. PathName specifies the MSMQ pathname of the queue, and is given in the general form MachineName\QueueName. Note that in this example, the MachineName part of the MSMQ pathname is a period (.), which indicates that the queue is located on the local computer.

The MSMQQueueInfo.Open method is used to create an instance of the actual queue object, MSMQQueue, and the variable Queue is set to refer to the new queue instance.

At this point, having gained access to the IIS_SDK_EXAMPLE queue, this sample now creates a new message object by instantiating MSMQMessage. The reference to the instance, Msg, is used to set the description and content of the message using the Label and Body properties. The Delivery property, which indicates whether express or recoverable delivery is used, is also set at this time. For this demonstration, it has been set to indicate that MSMQ is to use recoverable delivery.

With the message complete and the queue configured, the script is ready to send the message. The MSMQMessage.Send method is called to send the message to the queue pointed to by the reference Queue, and the queue is closed with the Close method. The message is now available to any other applications that have permission and inclination to access that queue.

Important   This sample requires that you install MSMQ on your host machine. It also requires, prior to running this sample for the first time, that you start MSMQ Explorer and create a new queue named IIS_SDK_EXAMPLE. MSMQ Explorer can also be used after the sample is run so that you can examine the results of the script's execution.

Location

The VBScript and JScript versions of this script are available in the IIS samples directory, at ...\asp\queuing\RecoverableDelivery_VBScript.asp and ...\asp\queuing\RecoverableDelivery_JScript.asp.