Salesforce

How Do I Send a Message to MSMQ? (Magic xpa 3.x)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Send a Message to MSMQ? (Magic xpa 3.x)

You can send messages to MSMQ easily in Magic xpa, using the MSMQ component. You have two basic options for sending messages:

  • You can use the use three different programs, to open, send messages, and close the queue. This is the most efficient if you have many messages to send.

  • Or, use the quick send program, which does all three steps in one.

We’ll cover both methods here.

Prerequisite: You need to have MSMQ installed on your computer, and have the Magic xpa MSMQ component loaded into your application. See How Do I Set Up My Computer for MSMQ?.

Using Open, Send, and Close

The first method uses three MSMQ programs:

  • Open Queue: Opens the Send queue, and returns the queue handle that will be used for sending messages.

  • Send Message: Send as many messages as needed, on the same queue handle.

  • Close Queue: closes the queue handle.

Detailed information about these three programs is found in Magic xpa Help. Here we will show a simple example.

1. Open Queue

Before you use a messaging queue, you need to open it. When you open the queue, you are determining if the queue is going to be used for reading or writing; if you are doing both at the same time, you will need two different queues.

Similarly, you need to open a unique queue for each destination. You can open a queue that is addressed to one particular computer, as shown in our example, or one that is addressed to a specific IP address, or use a public or private queue.

The first three parameters specify the queue. The queue can be of various types, and the computer address and queue name depend on what kind of queue you are accessing. For instance:

Queue Format Name

Computer Address

Queue Name

0: A computer name

The computer name as set up in Windows

The queue name as set up in Windows components

1: A TCP Address

The IP address

2: Public

Not required

The queue GUID

3: Private

The queue number

The queue number

The fourth parameter sets the Access method, which needs to be ‘W’ for ‘Write’ if it is a write queue. We set the Share method to ‘A’ because we are allowing other programs to write to the queue.

If the Open Queue program opened the queue successfully, it will return a positive integer, which is your queue handle. You need to store this number, because you will use it to send messages and to close the queue.

If the Open Queue program did not work successfully, it will return a negative integer. You can use this to give error messages, but it is easier to just use the MSMQ.PublicError event to give the error (see How Do I Trap Messaging Errors?).

Hint: For this example, we hard-coded the computer name for readability. You should use the function OSEnvGet ('COMPUTERNAME') to fetch the name of the computer you are working on, or store the computer name or IP address in a table, rather than hard-coding it.

2. Send Message

To send a simple message, you will use the following parameters:

  1. Queue handle: the queue handle you obtained from opening the queue.

  2. Message: The message you want to send. This should be a BLOB.

  3. Data type: For a simple text message, use ‘A’.

  4. Picture: This is only needed for numeric data.

  5. Transaction mode: we used ‘N’, because we aren’t using transactions.

  6. Transaction handle: not needed, because we aren’t using transactions.

You can send multiple messages without re-opening the queue.

3. Close Queue

After you are finished sending messages, you close the queue. Again, use the Queue handle you obtained in the Open Queue step.

Using Quick Send

Instead of using the Open-Send-Close sequence, you can use the Quick Send program, which does all three in one step. If you are only sending one message, this is an easier method.

Quick Send uses many of the same parameters as the three programs described above, but does them all in one step. For sending a simple text message, only a few of the parameters need to be specified, as shown.

Reference
Attachment 
Attachment