Writing MSMQ Applications

In MSMQ messaging, two or more applications communicate with each other indirectly and asynchronously by using message queues. The applications do not have to be running at the same time or even in the same operating environment. An application can communicate with another application by sending a message to a queue. The receiving application retrieves the message when it is ready.
A typical SAS program that uses MSMQ services performs the following tasks:
  1. A program must first either open an existing queue or create a new queue. A function is available to help find queues based on their property values. If opening an existing queue, the program supplies a queue identifier to select the appropriate queue. If creating a new queue, a queue identifier is returned to the program to be used in subsequent calls. The queue identifier is used by MSMQ in a distributed database that maintains information about users, queues, queue managers, host machines, and network layout. This database is referred to as the MSMQ Information Store (MQIS) and helps to insulate the application developer from the details of the network.
  2. When creating a queue, you can declare it public or private. Public queues are registered in the MQIS and can be accessed throughout the network. Private queues, on the other hand, can be accessed only by systems that know the queue's full pathname or format name. Other properties can be set when creating a queue such as security, message handling, and types of services provided by the queue. These same types of properties can also be retrieved from or set on a queue that has been opened.
  3. A program that has opened a queue can compose and send a message. To compose a message, a function is used to identify a data map that describes the format, the number and the type of parameters to be sent as part of the message. The data map is used by a function that creates a data descriptor of the actual values of the SAS variables to be included in the message. If your distributed application uses a Microsoft Transaction Server (MTS), then a transaction object can be used to send the message based on the success of the transaction.
  4. A program can also retrieve messages from an opened queue. MSMQ uses the concept of a cursor to identify the location of the message within a queue. A message can be read from the current cursor location, or you can see the next location. When a message is read, the program can elect to remove the message or leave it on the queue. In addition, a number of message properties such as security issues, size, identification, and statistics on the delivery can also be retrieved.
  5. After a program has sent or retrieved all its messages, queues can also be closed or deleted. This releases the resources that were allocated when the queue was opened or created.
Note: MSMQ uses several representations to identify a queue, such as format name, pathname, instance UUID, and queue handle. There are functions available that you can use to convert between representations.