Skip to content

Correlated Messaging with the MSMQ Process Step

Note: It is recommended that the Neuron process documentation be reviewed before running this sample. The documentation thoroughly describes each process component individually and describes how to configure each one as well as how to construct a process and associate it with a Neuron Publisher or Subscriber. See the Configuration Notes section at the end of this document for more information.

Overview

Sometimes it is necessary to correlate one-way messages with another system. Your process may need to send a one-way message to that system, and then receive one or more one-way messages as a response. Neuron provides an MSMQ Process Step that can be used for this particular scenario. The MSMQ Process Step can be configured to send or receive messages, either transactionally or non-transactionally. When receiving messages, the MSMQ Process Step can be configured to retrieve any message from the queue or only receive messages matching a correlation ID.

Process Components Demonstrated:

  • Exception (Try/Catch/Finally)
  • MSMQ (send and receive)
  • While
  • Decision
  • Break
  • Trace

Solution

This sample consists of one main process – MSMQ Process. This process starts by assigning a message correlation ID. This ID is used to send and receive correlated messages via MSMQ. The second step of the process sends a message to an MSMQ queue. This sample includes an external process that reads the message written to the queue by the previous step and writes several correlated messages to another queue that will be read by the next process step. The third step receives a single correlated message from another MSMQ queue.

Figure 1: The MSMQ “receive” process step properties. Notice that Correlate Receive is equal to True.

If a message is received, the process will loop and continue reading messages from that queue until the read times-out when no more messages are available. The code the check whether or not a message is received is:

object receivedMsg;
context.Properties.TryGetValue("msmq.ReceivedMessage", out receivedMsg);
return (bool)receivedMsg;

This code is entered as the condition for the While loop.

Figure 2: The Try block of the MSMQ Process process as displayed in the Neuron Process designer.

Running the Sample

Prerequisites

  1. The MSMQMessageProcessor application automatically creates the queues for this sample on the local server. If you need the queues created on a remote server you will need to update the code in this project.

Open the Sample

To open this sample, see the topic Using the Neuron Samples and select the Correlated Messaging with the MSMQ Process Step sample.

Run the Sample

  1. The Visual Studio solution MSMQMessageProcessor was automatically opened when you configured the sample. Start this sample by pressing F5.
  2. Navigate to the Process Designer by selecting the Processes tab in the left panel of Neuron Explorer.
  3. Select the MSMQ Process process from the list on the left of the designer.
  4. On the Process Designer toolbar click the Test button . This will open the Edit Test Message Dialog shown in Figure 3.
Figure 3: Edit Test Message dialog displaying the test Orders message for this example.
  1. The contents of the message used in this sample do not matter. Either keep the existing message or type in your own.
  2. Click the OK button on the Edit Test Message dialog. Once the dialog is closed the process will begin execution.
  3. As the process runs each step will be highlight in green as it is executed. In addition, any trace messages will be visible in the Trace Window. As you visually follow the execution not the sequence of steps. When the process completes, the Trace Window should look similar to what is shown in Figure 8.
Figure 4: MSMQ Process process test run displaying results and exceptions in the Trace Window.

Configuration Notes

All processes with the exception of the Code process step are configured by selecting and setting their properties in the property grid located at the bottom right of the process designer. The Code process step is configured by selecting the “Edit” option from the short cut menu that is available when right-clicking the Code step in the process designer. See the process documentation for more information.

Figure 5: The Neuron Process Designer displaying the MSMQ Process process. Property Grid at the bottom right displaying the properties of MSMQ process step.
Was this article helpful?
Dislike 0
Previous: Exception Handling
Next: Dynamic Routing by Header Property