The standard Java networking APIs, as well as remote object systems such as RMI and CORBA, operate by default under the assumption of synchronous communications. In other words, if a client makes a request of a remote server (e.g., opens a socket and attempts to read some data from it or makes a remote method call on a remote object), the thread that made the request will block until the response comes back from the server. In some situations, it might be necessary or useful to engage in asynchronous communications (e.g., a client sends a request to the server and then continues doing other work, while the server possibly invokes some kind of callback on the client when the request is complete). This is where the Java Message Service (JMS) comes in. JMS is an API for performing asynchronous messaging. JMS is principally a client-focused API, in that it provides a standard, portable interface for Java/J2EE clients to interact with native message-oriented middleware (MOM) systems like IBM WebSphere MQ, SonicMQ, and so on. JMS isn't intended to be a platform for implementing a full messaging system, since it doesn't provide a service provider interface for all of the internals of a message service implementation. In a sense, JMS plays a role with native messaging systems that is analogous to the role that JDBC plays with relational database systems or the role JNDI plays with naming and directory services. Java clients using JMS to interact with messaging systems can (ostensibly) be more easily ported from one native messaging system to another, because they are insulated from the proprietary particulars of the underlying vendor's message system. The JMS API is provided in the javax.jms package. The material in this chapter is based on Version 1.1 of the JMS specification, released in April 2002, which is the most current version at this writing and the version that is required in J2EE 1.4 environments. J2EE 1.3 servers use JMS 1.0we highlight relevant issues between these JMS versions in this chapter. The examples in the chapter have been tested against the JMS services embedded in the JBoss 4.0 server. |