Overview


Before diving in to programming Message Queuing, this section discusses the basic concepts of messaging and compares it to synchronous and asynchronous programming. With synchronous programming, when a method is invoked, the caller has to wait until the method is completed. With asynchronous programming, the calling thread starts the method that runs concurrently. Asynchronous programming can be done with delegates, class libraries that already support asynchronous methods (for example, Web service proxies, System.Net, System.IO classes), or by using custom threads (see Chapter 18, “Threading and Synchronization”). With both synchronous and asynchronous programming, the client and the server must be running at the same time.

Although Message Queuing operates asynchronously, because the client (sender) does not wait for the server (receiver) to read the data sent to it, there is a crucial difference between Messaging Queuing and asynchronous programming: Message Queuing can be done in a disconnected environment. At the time data is sent, the receiver can be offline. Later, when the receiver goes online, it receives the data without the sending application to intervene.

You can compare connected and disconnected programming with talking to someone on the phone and sending an e-mail. When talking to someone on the phone, both participants must be connected at the same time. The communication is synchronous. With an e-mail, the sender isn’t sure when the e-mail will be dealt with. People using this technology are working in a disconnected mode. Of course the e-mail may never be dealt with - it may be ignored. That’s in the nature of disconnected communication. To avoid this problem, it is possible to ask for a reply to confirm that the e-mail has been read. If the answer doesn’t arrive within a time limit, you may be required to deal with this “exception.” This is also possible with Message Queuing.

In some ways Message Queuing is e-mail for application-to-application communication, instead of person-to-person communication. However, this gives you a lot of features that are not available with mailing services, such as guaranteed delivery, transactions, confirmations, express mode using memory, and so on. As you see in the next section, Message Queuing has a lot of features useful for communication between applications.

With Message Queuing you can send, receive, and route messages in a connected or disconnected environment. Figure 39-1 shows a very simple way of using messages. The sender sends messages to the message queue, and the receiver receives messages from the queue.

image from book
Figure 39-1

When to Use Message Queuing

One case where Messaging Queuing is useful is when the client application is often disconnected from the network (for example, when a salesperson is visiting a customer onsite). The salesperson can enter order data directly at the customer’s site. The application sends a message for each order to the message queue that is located on the client’s system (see Figure 39-2). As soon as the salesperson is back in the office, the order is automatically transferred from the message queue of the client system to the message queue of the target system, where the message is processed.

image from book
Figure 39-2

In addition to using a laptop, the salesperson could use a Pocket Windows device where Message Queuing is available.

Message Queuing can also be useful in a connected environment. Imagine an e-commerce site (see Figure 39-3) where the server is fully loaded with order transactions at certain times, for example, early evening and weekends, but the load is low at nighttime. A solution would be to buy a faster server or to add additional servers to the system so that the peaks can be handled. But there’s a cheaper solution: flatten the peak loads by moving transactions from the times with higher loads to the times with lower loads. In this scheme, orders are sent to the message queue, and the receiving side reads the orders at the rates that are useful for the database system. The load of the system is now flattened over time so that the server dealing with the transactions can be less expensive than an upgrade of the database server(s).

image from book
Figure 39-3

Message Queuing Features

Message Queuing is part of the Windows operating system. The main features of this service are:

  • Messages can be sent in a disconnected environment. It is not necessary for the sending and receiving application to run at the same time.

  • With express mode, messages can be sent very fast. Express mode messages are just stored in memory.

  • For a recoverable mechanism, messages can be sent using guaranteed delivery. Recoverable messages are stored within files. They are delivered even in cases when the server reboots.

  • Message queues can be secured with access control lists to define which users can send or receive messages from a queue. Messages can also be encrypted to avoid network sniffers reading them. Messages can be sent with priorities so that high-priority items are handled faster.

  • Message Queuing 3.0 supports sending multicast messages.

  • With transactional message queues, messages can take part in a DTC transaction (see Chapter 38, “Enterprise Services,” for transactions with the DTC).

Tip 

Because Message Queuing is part of the operating system, you cannot install Message Queuing 3.0 on a Windows 2000 system. Message Queuing 3.0 is part of Windows Server 2003 and Windows XP.

The remainder of this chapter discusses how these features can be used.




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

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