Message Queuing C# Help

System Messaging is a namespace that includes classes for reading and writing messages with the Message Queuing facility of the Windows operating system. Messaging can be used in a disconnected scenario where the client and server needn’t be running at the same time.

This chapter looks at the following topics:

  1. An overview of Message Queuing
  2. Message Queuing architecture
  3. Message queue administrative tools
  4. Programming Message Queuing
  5. Course order sample application.
  6. Message Queuing with WCF


Before diving into 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,  libraries that already support asynchronous methods (for example, Web service proxies, System. Net, and System. 10 classes), or by using custom threads (see Chapter 19, “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, there is a crucial difference between Message 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 intervention from the sending application.

You can compare connected and disconnected programming with talking to someone on the phone and sending an email. When talking to someone on the phone, both participants must be connected at the same time; the communication is synchronous. With an email, the sender isn’t sure when the email will be dealt with. People using this technology are working in a disconnected mode. Of course the email 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 email 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 email 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 45-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.

Figure 45-1

Figure 45-1

When to Use Message Queuing

One case in which Message 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 IP<;a~don the client’s system (see Figure 45-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.

In addition to using a laptop, the sales person 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 45-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  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).

Figure 45-2

Figure 45-2

Figure 45-3

Figure 45-3

Message QueuIng Features

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

  1. Messages can be sent in a disconnected environment. It is not necessary for the sending and receiving applications to run at the same time.
  2. With express mode, messages can be sent very quickly. Express-mode messages are just stored in memory.
  3. 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.
  4. Message queues can be secured with access-controllists 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.
  5. Message Queuing 3.0 supports sending multicast messages.
  6. Message Queuing 4.0 supports poison messages. A poison message is one that isn’t getting resolved. You can define a poison queue where unresolved messages are moved. For example, if the job after reading the message from the normal queue was to insert it into the database, but the message did not get into the database and thus this job failed, it would get sent to the poison queue. It is someone’s job to handle the poison queue – and that person should deal with the message in a way that resolves it.

Because Message Queuing is part of the operating system, you cannot install Message Queuing 4.0 on a Windows XP or Windows Server 2003 system. Message Queuing 4.0 is part of Windows Server 2008 and Windows Vista.

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

Message Queuing Products

Message Queuing 4.0 is part of Windows Vista and Windows Server 2008. Windows 2000 was delivered with Message Queuing 2.0, which didn’t have support for the HTTP protocol and multicast messages. Message Queuing 3.0 is part of Windows XP and Windows Sever 2003. When you use the like “Turn Windows Features on or off” in Configuring Programs and Features of Windows Vista, there i.e a separate section for Message Queuing options. With this section, you can select these components:

  1. Microsoft Message Queue (MSMQ) Server Core – The Core subcomponent is required for base functionality with Message Queuing.
  2. Active Directory Domain Services Integration – With the Active Directory Domain Services Integration, message queue names are written to the Active Directory. With this option, it is
    possible to find queues with the Active Directory integration, and to secure queues.with Windows users and groups.
  3. MSMQ HTTP Support – MSMQ HTTP Support allows you to send and receive messages using the HTTP protocol.
  4. Triggers – With triggers, applications can be instantiated on the arrival of a new message.
  5. Triggers – With triggers, applications can be instantiated on the arrival of a new message.
  6. MSMQ DCOM Proxy – With the DCOM proxy, a system can connect to a remote server by using the DCOM API .

.When Message Queuing is installed, the Message Queuing service (see Figure 45-4) must be started. This service reads and writes messages and communicates with other Message Queuing servers to route messages across the network,.

Figure 45-4

Figure 45-4

Posted on October 31, 2015 in Message Queuing

Share the Story

Back to Top
Share This