O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
Chapter 6. Guaranteed Messaging, Transactions,<br />
Acknowledgments, and Failures<br />
We have been introducing the notion of guaranteed messaging in bits and pieces<br />
throughout the book. Until now, we have assumed that you would take our word that<br />
guaranteed messaging ensures that messages are faithfully delivered once-and-only-once<br />
to their intended consumers.<br />
This chapter examines why guaranteed messaging works, and provides a thorough<br />
discussion of the subject. We will examine the message acknowledgment protocols that are<br />
part of guaranteed messaging, and how to use client acknowledgments in applications. We<br />
will explore the design patterns of JMS that enable you to build guaranteed messaging into<br />
applications, and discuss failure scenarios, the rules that apply to recovery, and how to deal<br />
with recovery semantics in a JMS application.<br />
6.1 Guaranteed Messaging<br />
Guaranteed messaging is more than just a mechanism for handling disconnected<br />
consumers. It is a crucial part of the messaging paradigm, and is the key to understanding<br />
the design of a distributed messaging system. There are three main parts to guaranteed<br />
messaging: message autonomy, store-and-forward, and the underlying message<br />
acknowledgment semantics.<br />
Before we discuss the parts of guaranteed messaging, we need to review and define some<br />
new terms. A JMS client application uses the JMS API. Each JMS vendor provides an<br />
implementation of the JMS API on the client, which we call the client runtime. In addition<br />
to the client runtime, the JMS vendor also provides some kind of message "server" that<br />
implements the routing and delivery of messages. The client runtime and the message<br />
server are collectively referred to as the JMS provider. Regardless of the architecture used<br />
by a JMS provider, the logical parts of a JMS system are the same. The number of<br />
processes and their location on the network is unimportant for this discussion. (In Chapter<br />
7, we'll see that some providers use a multicast architecture in which there is no central<br />
server.) The upcoming sections make use of diagrams that describe the logical pieces, and<br />
do not necessarily reflect the process architecture of any particular JMS provider.<br />
A provider failure refers to any failure condition that is outside of the domain of the<br />
application code. It could mean a hardware failure that occurs while the provider is<br />
entrusted with the processing of a message, or an unexpected exception, or the abnormal<br />
end of a process due to a software defect, or network failures.<br />
6.1.1 <strong>Message</strong> Autonomy<br />
<strong>Message</strong>s are self-contained autonomous entities. This fact needs to be foremost in your<br />
mind when designing a distributed messaging application. A message may be sent and<br />
resent many times across multiple processes throughout its lifetime. Each JMS client along<br />
the way will consume the message, examine it, execute business logic, modify it, or create<br />
new messages in order to accomplish the task at hand.<br />
84