INFO: Writing an MSMQ Application for Offline Operation

ID: Q172688


The information in this article applies to:
  • Microsoft Message Queue Server version 1.0


SUMMARY

You may want to write a Microsoft Message Queue Server (MSMQ) application for a single computer to generate and queue messages while offline and then, when later connected to the network, forward the messages to a remote application or notify the remote application that the local queue of messages is now available for it to open and read.

IMPORTANT: When writing an offline application using local queues, define the queues to be Recoverable. Using Express queues may lead to loss of messages.

The configuration targeted for individual offline operation is the Independent Client. The Dependent Client is incapable of operating offline. The Windows NT Server and SQL Server requirements of a Site controller configuration, while simpler to code for, would probably be impractical for a single offline user.

When the offline computer is an Independent client, you need to write the offline portion of the application carefully to avoid using APIs that query the Message Queue Server Information Store (MQIS). The MQIS is held only on site controllers (PEC/PSC/BSC). Using any API, like MQLocate, that requires consultation of the MQIS would attempt to generate network traffic, causing an error or timeout in the application.


MORE INFORMATION

To open a handle to a queue with no connection to a Falcon MQIS server you can do either of the following:

  • Use the DIRECT= format.

    -or-


  • Use the GUID of the queue ("PUBLIC=" format).


After the queue is open, all messages will be stored by the QM for the application until connectivity is regained.

DIRECT= Format

This format includes the target computer's name, or the target computer's network address, and local queue name of the target queue. This method can only be used when the target computer is directly connectable (one MSMQ hop) from the source computer.

Falcon routing will not take place with such addressing. The message is sent directly to the remote computer's queue as soon as the sending client regains connectivity with the remote computer. No access to the MQIS is required.

To specify the format name, you can do either of the following:

  • Use the computer name (for example, \\mymachine).

    -or-


  • Use the TCP/IP address (for example, 203.204.205.206).


This method forces the application to store the address information of the target computer before disconnecting. If you choose to use the TCP/IP address, this can be problematic if you are also using DHCP, because the target computer may have changed network addresses since the source computer stored the address. While the computer name may have been changed while the source computer was disconnected, this is far less likely to have occurred.

PUBLIC= Format

This format requires your application to cache this GUID before disconnecting. The MQOpenQueue() will succeed offline, and then you can send messages, and close the queue handle, and quit the application. All messages will be stored by the QM for the application.

A connection to the MQIS server is eventually required using this method. To actually transfer messages to the remote destination queue , MSMQ needs to consult an MQIS server in order to resolve the GUID into a network address. If the MQIS server is down when the sending computer regains connectivity, the sending computer will not send the messages.

Sample Code


   Private Sub OpenQueueOffline()
       Dim qinfo As MSMQQueueInfo
       Set qinfo = New MSMQQueueInfo
       Dim q As New MSMQQueue

       txtDirectFormatName = "DIRECT=TCP:157.57.12.62\wiley"

       qinfo.strPathName = ""
       qinfo.strFormatName = ""
       qinfo.strLabel = ""
       qinfo.strFormatName = txtDirectFormatName

       on error goto ErrorHandler
       Set q = qinfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)

       If q.isOpen Then
          MsgBox "The queue " + qinfo.strPathName + " is open."
       Else
          MsgBox "The queue " + qinfo.strPathName + " is not open!"
       End If

       'Clean up
       qinfo.strPathName = ""
       Set qinfo = Nothing
       Set q = Nothing
       Exit Function

    ErrorHandler:
       msgbox "error while opening queue: " qinfo.strPathName
       Exit Function

   End Sub 


REFERENCES

For more information, please see the MSMQ Offline Support section of the MSMQ software development kit (SDK).

Additional query words: app machine

Keywords : kbprg MQAPI MQProg MQQueue
Version : winnt:1.0
Platform : winnt
Issue type : kbhowto kbinfo


Last Reviewed: August 27, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.