July 20, 2011, 2:52 a.m.
posted by franni
Integration Styles and Messaging
So far, we've considered the issue of object distribution, and have shown how the most common mechanisms in Java have solved this problem. However, as we discussed at the beginning of the chapter, there are many ways to handle program-to-program communication in Java. The general problem of program-to-program communication has been a constant and ongoing source of research, development, and heartache almost since the dawn of the computer age. In particular, five different ways of program integration have risen to the forefront as the most commonly implemented solutions to this problem. Let's examine them so that we can understand the most common, and attractive, alternatives to object distribution in particular situations.
As compared to the other four communication mechanisms, relatively few developers have had exposure to messaging and MOMs, and developers in general are not familiar with the idioms and peculiarities of this communication's platform. As a result, we have seen many programmers try to use messaging in an inappropriate way, or to develop systems that do not take advantage of the capabilities and strengths of messaging.
1 JMS and MOMs
A simple way to understand what a messaging system does is to consider voice mail (as well as answering machines) for phone calls. Before voice mail, when someone called, if the receiver could not answer, the caller hung up and called back later to see if the receiver would answer. With voice mail, when the receiver does not answer, the caller can leave a message; later, the receiver (at his convenience) can listen to the messages queued in his mailbox. Voice mail enables the caller to leave a message now so that the receiver can listen to it later, which is often a lot easier than trying to get the caller and the receiver on the phone at the same time. Voice mail bundles (at least part of) a phone call into a message and queues it for later; this is essentially how messaging works.
In enterprise computing, messaging makes communication between processes reliable, even when the processes and the connection between them are not.
J2EE defines a standard API for messaging. This is the JMS. There are a number of products available for embedding messaging into and between applications. One of the oldest and best-known messaging products is IBM's WebSphere MQ. WebSphere MQ implements the JMS API. WAS includes a limited version of MQ Series, called WebSphere Embedded Messaging, that allows WebSphere application servers to communicate with other WebSphere application servers, and also allows Java application clients to communicate with WebSphere servers. However, WebSphere Embedded Messaging does not support connection to other programs, such as legacy systems. For that, you should use the WebSphere MQ product, which is fully compatible with WAS.
Besides WebSphere MQ, many other products implement the JMS API, and it is possible to use these products with WAS, but the details of managing that integration are beyond the scope of this book. However, we will discuss how WebSphere EJBs interact with the JMS messaging API in Chapter 27 and show you how to take advantage of asynchronous communication with EJBs.