With asynchrony comes the need for reliability. When an application sends an asynchronous message, there often needs to be some sort of assurance that the message will get to where it needs to go. There are three key parts to reliable messaging: message autonomy, store and forward, and the underlying message acknowledgment semantics. 5.3.1 Message Autonomy Messages are self-contained, autonomous entities that represent a business transaction. Once a message producer sends a message, its role is completed. If the message is properly designated for reliable delivery, the messaging system guarantees that it is received by any interested parties, and the ESB ensures that it arrives in the desired target data format. This contract between a sending client and the messaging system is much like the contract between a JDBC client and the database. Once the data is reliably delivered to the messaging server, it is considered "safe" and out of the hands of the client. 5.3.2 Store and Forward MOM provides message queuing and guaranteed delivery semantics, which ensure that "unavailable" applications will get their data queued and delivered at a later time. The message delivery semantics cover a range of delivery options, from exactly-once delivery to at-least-once delivery to at-most-once delivery. In the exactly-once (a.k.a. once-and-only-once) delivery mode, the messaging system guarantees that the message will arrive at the intended destination no matter what, and will never be sent more than once. Even in the pub/sub model, where multiple receivers may consume a copy of a broadcasted message, the rules still apply within the relative view of each consumer. Exactly-once delivery guarantee is accomplished in part by the use of a technique known as store and forward (see Figure 5-10). Figure 5-11. MOM uses a store-and-forward mechanism as part of the solution to guarantee once-and-only-once delivery of messages There is much more to once-and-only-once delivery than what is illustrated in Figure 5-10. Store and forward is accompanied by a set of rules for governing message acknowledgments at the wire protocol level, and for handling transactional recovery if the application or the messaging system fails. This behavior will be explored momentarily. At-most-once delivery is a less stringent Quality of Service (QoS) setting on a message, which means that the messaging system is allowed to occasionally lose a message in the event of a hardware, software, or network failure. There are valid business cases in which this is acceptable behavior. A common example is a stock feed application in which the system is set up to cycle through ticker symbols every few minutes. If the broadcast of a particular ticker symbol does not reach its intended destination, another one will be along shortly. Typically, the performance and throughput of messages using at-most-once delivery are much higher (up to 10 times the throughput) than with exactly-once. In addition to guaranteed delivery mode, most messaging systems have options for message ordering guarantees. Message ordering means that messages are delivered to the receiver in the same order in which they are sent by the sender. A variety of things can affect the ordered delivery of messages. In cases of failure and recovery, for example, messages may be held in a queue and redelivered to an application at a later time than the messages that were sent while the system was unavailable. Typically there will be settings to control whether order is guaranteed globally across the entire system, guaranteed between two distinct endpoints, or not guaranteed at all. 5.3.3 Message Persistence When messages are marked persistent, it is the responsibility of the messaging system to utilize a store-and-forward mechanism to fulfill its contract with the sender. The storage mechanism is used for persisting messages to disk to ensure that it can be recovered if there is a failure of either the messaging system or the consuming client. The forwarding mechanism is responsible for retrieving messages from storage, and subsequently routing and delivering them. 5.3.4 Message Acknowledgments Message acknowledgment at the wire protocol level is a key factor in guaranteed messaging. The acknowledgment protocol allows the messaging system to monitor the progress of a message so that it knows whether the message was successfully produced and consumed. With this knowledge, the messaging system can manage the distribution of messages and guarantee their delivery. In the loosely coupled asynchronous environment of MOM, senders and receivers (producers and consumers) are intentionally decoupled from each other. Hence, the roles and responsibilities are divided among the message producer, the message server, and the message consumer. |