Asynchronous
Message Queuing
Using the
.NET and COM+ Services
Gopalan Suresh Raj
Note |
To
work with any of these samples, you will need the
following: .........................................Microsoft .NET SDK |
The coolest thing is that MSMQ (and the COM+ Queued Components wrapper technology) comes with Windows 2000. You don't need SQL Server, or even the Windows Active Directory, to use it.
The .NET framework uses the System.Messaging namespace to leverage the Message Queuing Services provided by COM+.
I will illustrate this by developing a Command-Line based Asynchronous Messaging Receiver and Server. The Server can send multiple messages which are queued in order and read by the client application.
Develop the Asynchronous Message Queuing Client and Server
Messages that are sent from different instances of the Server reach the Messaging Queue which queues them in an internally. These messages can at any time be retrieved from the queue asynchronously by the Client.
1. Develop The Server Application : MSMQServer.EXE
.
MSMQServer.cs | ||
|
2. Develop the Client Application
: MSMQClient.EXE
.
MSMQClient.cs | ||
|
3. Compile the Server and the Client Applications
MS-DOS Command Prompt |
H:\csharpForays\MSMQ>csc /debug+ /r:system.messaging.dll MSMQServer.cs Microsoft (R) C# Compiler Version 7.00.8905 [NGWS runtime 2000.14.1812.10] Copyright (C) Microsoft Corp 2000. All rights reserved. H:\csharpForays\MSMQ> H:\csharpForays\MSMQ> H:\csharpForays\MSMQ>csc /debug+ /r:system.messaging.dll MSMQClient.cs Microsoft (R) C# Compiler Version 7.00.8905 [NGWS runtime 2000.14.1812.10] Copyright (C) Microsoft Corp 2000. All rights reserved. H:\csharpForays\MSMQ> H:\csharpForays\MSMQ> |
4. Run One Instance of the Client (MSMQClient.EXE) and Multiple Instances of the Server (MSMQServer.EXE)
Remember to startup the Message Queuing Component Service and make sure it's running before executing either the Client or the Server applications.
i.e., Administrative Tools->Component Services->Services (Local)->Message Queuing
MS-DOS Command Prompt |
H:\csharpForays\MSMQ> H:\csharpForays\MSMQ>MSMQServer testQueue "This is a test" H:\csharpForays\MSMQ>start MSMQClient testQueue H:\csharpForays\MSMQ>MSMQServer testQueue "Hello Athul..." H:\csharpForays\MSMQ>MSMQServer testQueue "This is Gopalan..." H:\csharpForays\MSMQ>MSMQServer testQueue "How are you doing?" H:\csharpForays\MSMQ> |
The Client Window that opened up as a result of executing the "start" DOS Command appears on the screen as follows.
H:\csharpForays\MSMQ\MSMQClient.exe |
Press enter to stop the program... The Message Received Reads :This is a test The Message Received Reads :Hello Athul... The Message Received Reads :This is Gopalan... The Message Received Reads :How are you doing? |
Download the entire source code as a zip file.
click here to go
to
My
Advanced C#/.NET Tutorial Page...
click here to go
to
My
Microsoft Message Queue (MSMQ) Page...
About the Author... |
Gopalan Suresh Raj is a Software Architect, Developer and an active Author. He is contributing author to a couple of books "Enterprise Java Computing-Applications and Architecture" and "The Awesome Power of JavaBeans". His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia© site (http://www.execpc.com/~gopalan) or mail him at gopalan@execpc.com. |
This site was developed and is maintained by Gopalan Suresh Raj This page has been visited times since October 26, 2000. |
Last Updated : Oct 26, '00 |
Copyright (c) 1997-2000, Gopalan Suresh Raj - All rights reserved. Terms of use. |
All products and companies mentioned at this site are trademarks of their respective owners. |