Correlated Messaging with the MSMQ Process Step
- Home
- Neuron ESB
- Development
- Samples and Walkthroughs
- Process Samples
- Correlated Messaging with the MSMQ Process Step
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.
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.
Running the Sample
Prerequisites
- 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
- The Visual Studio solution MSMQMessageProcessor was automatically opened when you configured the sample. Start this sample by pressing F5.
- Navigate to the Process Designer by selecting the Processes tab in the left panel of Neuron Explorer.
- Select the MSMQ Process process from the list on the left of the designer.
- On the Process Designer toolbar click the Test button . This will open the Edit Test Message Dialog shown in Figure 3.
- The contents of the message used in this sample do not matter. Either keep the existing message or type in your own.
- Click the OK button on the Edit Test Message dialog. Once the dialog is closed the process will begin execution.
- 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.
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.