Article ID: 555298 - View products that this article applies to.
This article describes how to correlate request/response messages by using System.Messaging.
The following article explains how to correlate request/response messages by using System.Messaging.
It applies to a typical scenario where you can find one or more client applications that require information and processing from a central server application. Both applications client and server, exchange response and request information by sending messages to msmq queues.
The clients running on different machines send request messages to the
server, which has to send back response messages.
Two questions arise here:
If the server receives several messages from different clients, how does it know which of the clients' queues it needs to send the response to?
If the client sends several messages to the server, how does it know which of the request messages each response message corresponds to?
Any client application sends a request in a message to the server application and saves the Message.Id in memory. The server application receives the message, processes the request and sends a response message, setting its Message.CorrelationId property with the received Message.Id. Then the client application looks up for the message response based in the request Message.Id.
The other topic that has to be covered by the server application is to attend to many clients queuing theirs requests. The client sets the Message.ResponseQueue property of the request message and sends it to the server. This property contains information about the queue where the client wants to receive the response message. The server receives the request message with the corresponding Message.ResponseQueue property, so it already has the specifications to address the reply.
The following example shows two applications, a client and a server, correlating messages and delivering response message to specified response queues.
Both client and server's queues already exist. The server application runs in a computer called "ServerPC" with a public queue called "ServiceA" from where it receives the request messages. The client application resides in another computer with a private queue called "ServiceAResponses" where response messages will be arriving.
Note: For better performance and failure avoiding receive message only from local Queues.
The logic sequence of the following example should be
Important Note: ReceiveByCorrelationId uses sequence search to find a message in a queue. Use it with carefulness; it might be inefficient when a high number of messages reside in a queue.
Article ID: 555298 - Last Review: April 23, 2005 - Revision: 1.0
COMMUNITY SOLUTIONS CONTENT DISCLAIMER
MICROSOFT CORPORATION AND/OR ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY, RELIABILITY, OR ACCURACY OF THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN. ALL SUCH INFORMATION AND RELATED GRAPHICS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT AND/OR ITS RESPECTIVE SUPPLIERS HEREBY DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THIS INFORMATION AND RELATED GRAPHICS, INCLUDING ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, WORKMANLIKE EFFORT, TITLE AND NON-INFRINGEMENT. YOU SPECIFICALLY AGREE THAT IN NO EVENT SHALL MICROSOFT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, PUNITIVE, INCIDENTAL, SPECIAL, CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF USE, DATA OR PROFITS, ARISING OUT OF OR IN ANY WAY CONNECTED WITH THE USE OF OR INABILITY TO USE THE INFORMATION AND RELATED GRAPHICS CONTAINED HEREIN, WHETHER BASED ON CONTRACT, TORT, NEGLIGENCE, STRICT LIABILITY OR OTHERWISE, EVEN IF MICROSOFT OR ANY OF ITS SUPPLIERS HAS BEEN ADVISED OF THE POSSIBILITY OF DAMAGES.
Contact us for more help
Connect with Answer Desk for expert help.