Chapter 12. Using Message Queues

I l @ ve RuBoard

You learned in the last few chapters how to send messages between processes that are running concurrently, either on the same computer or on different computers. But sometimes a client application might need to send a message to a server process that is not executing at that time. Rather than have the message be rejected and raise an exception, it might be better to store the message and forward it to the target server process when it eventually does start running. In a similar scenario, you might need to send a message to a server process when the client is disconnected from the network. Again, it would be useful to store and forward the message once a network connection has been established.

Consider the example of a traveling salesperson who visits clients and places orders for goods using a local application running on a laptop computer. The order details can be stored on the laptop and then downloaded to the server process that handles orders when the salesperson arrives back in the office and connects the laptop to the LAN.

Of course, applications that use this model of processing must be structured not to expect an immediate response from a server when a request is sent. Instead, such applications can periodically poll for a reply, use some sort of event infrastructure to subscribe to an event that's raised when a reply arrives, or even be designed to not expect a response at all. These strategies imply a need for reliability and the assurance that once a client application has dispatched a message it will be received by a server process or that the client will at least be informed if the message is not delivered within a given period of time. Security is another issue. Messages should not be compromised while they're waiting to be sent, or during transmission.

Building the infrastructure needed to handle the myriad situations that can arise when you design asynchronous distributed applications would be a time consuming and expensive process. Fortunately, this functionality is already available when you base your applications on Microsoft Windows, through Microsoft Message Queuing.

Message queuing has been an available in Windows since the days of the Windows NT Option Pack, which supplied Microsoft Message Queue (MSMQ) version 1.0. With the advent of Windows 2000, MSMQ became an integral part of the operating system, and version 3.0, officially called Message Queuing 3.0, is available as part of the Windows XP platform. Other vendors have also produced their own message queuing solutions, many of which predate MSMQ. IBM's WebSphere MQ (formerly MQSeries) is an example.

When you build distributed applications, it's important to be able to integrate across vendor platforms, so a selection of bridging components are also available from third-party integrators. Microsoft recommends the Envoy MQ Client from Envoy Technologies (http://www.envoytech.com) for connecting MSMQ and Message Queuing 3.0 services to non-Windows platforms. (Envoy Technologies also supplies implementations of MSMQ for operating systems other than Windows, such as Linux and Sun's Solaris.)

In this chapter, we'll look at how to write J# applications that use Message Queuing 3.0 for communicating between processes. In particular, we'll examine the architecture of Message Queuing 3.0 and look at how to program against message queues using the classes available in the .NET Framework Class Library.

I l @ ve RuBoard


Microsoft Visual J# .NET (Core Reference)
Microsoft Visual J# .NET (Core Reference) (Pro-Developer)
ISBN: 0735615500
EAN: 2147483647
Year: 2002
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net