Web services provide a powerful architecture for integrating applications running in heterogeneous, distributed environments. Open standards make Web services interoperable across these environments. For example, the Simple Object Access Protocol (SOAP) and HTTP transport standards allow for an interoperable messaging mechanism. Although standards compliance and the associated interoperability remain the most important objectives of Web services, they are not the only ones. Consider a mission-critical system that needs to achieve zero down time and zero data loss. Using SOAP over HTTP messaging is not sufficient because HTTP does not guarantee message delivery, so a more reliable and scalable messaging mechanism is required. In the Java? world, Java Message Service (JMS) can be used to achieve such messaging support. This article will discuss the motivations behind JMS Web services, present a use case scenario to demonstrate the use of SOAP over JMS, and then show you in detail how to create a JMS Web service using IBM? WebSphere? Studio V5.1.
In a distributed computing environment, data exchange between applications is governed by the underlying messaging protocol. To satisfy Java applications that require enterprise messaging support, Sun? Microsystems introduced JMS, which is a common set of APIs and frameworks that support reliable, scalable, portable, and asynchronous messaging among J2EE applications. As JAX-RPC and JSR-109 become integral parts of the J2EE 1.4 specification in order to form the basis of enterprise Web services, support for JMS-based Web services is expected. IBM has recognized this fact and introduced a Web service implementation in WebSphere Application Server V5 that supports JMS messaging.
JMS supports two basic styles of message-based communications: point-to-point and publish-subscribe (pub-sub). Point-to-point lets multiple receivers listen for messages that arrive in a JMS queue, and the arrived message can be retrieved by only one receiver. Once the message is retrieved, it is deleted from the JMS queue and is no longer available to other receivers. Pub-sub communication lets multiple subscribers listen for messages that get published in a JMS topic. Unlike point-to-point communication, a message published in a JMS topic does not get deleted once it is retrieved. It stays on the topic and is made available for all subscribers.
Building on top of JMS, JMS Web services support two messaging styles: one-way request messaging and two-way request and response messaging. One-way request messaging lets a Web service client unblock when the request message reaches a JMS queue or topic. Two-way request and response messaging blocks a Web service client until the response message is received.
This section will show you how JMS Web services work in WebSphere Application Server V5. Figure 1 below shows a workflow diagram for one-way request messaging and two-way request and response messaging to a single receiver. Both JMS queue or JMS topic can be used for one-way request messaging, but JMS queue is the recommended approach because it results in better performance. For two-way request and response messaging, a JMS queue must be used, because JMS topic does not support point-to-point communication.
Figure 2 shows a workflow diagram for one-way request messaging to multiple receivers. This messaging style resembles the JMS pub-sub structure, so a JMS topic must be used in this case.
JMS sender is an internal handler that is a part of the SOAP engine's pluggable transport mechanism. It is responsible for delivering the SOAP request message to the destination queue or topic, and receiving the SOAP response message, if applicable. JMS listener is basically a message-driven bean that dispatches an incoming request to the SOAP engine for processing. It is also responsible for sending the response message to the reply queue. WebSphere Studio supports both of the above messaging styles. The following section presents a use-case scenario on the use of JMS Web services.
Since SOAP is transport-independent and can be bound to any protocol, SOAP over JMS is an alternative messaging mechanism to the standard SOAP over HTTP messaging. Although both of them serve as a communication channel between a Web service provider and a Web service client, they are very different. When interoperability is the driving factor, use SOAP over HTTP because it is standardized by the Web Service Interoperability (WS-I) organization. When reliability, scalability, and asynchronous messaging are the key factors, consider SOAP over JMS.
SOAP over JMS ensures reliability because message delivery is guaranteed. Messages sent by a Web services provider or Web services client are placed onto a queue or topic and stored in persistent storage. In case of a communication failure, the failing message is retrieved from the persistent storage and re-sent until transmission is successful, which is extremely useful in transaction- and data- critical systems. Businesses that use Enterprise Application Integration (EAI) should find SOAP over JMS appealing because it boosts confidence when exchanging critical data between client and server.
Scalability is another advantage with SOAP over JMS. Unlike HTTP, JMS can support high-volume connections, even for services that get tens of thousands of connections per second.
Asynchronous messaging lets a client invoke a service without waiting for the response. Asynchronous invocation can be implemented by both synchronous and asynchronous transport. JMS as an asynchronous transport can provide a correlator mechanism for associating response messages with request messages. It also lets a client query the status of its requests, and retrieve the responses independently. These features, which HTTP lacks, make the implementation of asynchronous invocation easier for both service requestor and service provider.
The following scenario illustrates a possible configuration that lets businesses take advantage of the interoperability aspect of SOAP over HTTP messaging, as well as the reliability aspect of SOAP over JMS messaging. Figure 3 shows the configuration of a Web services gateway that uses SOAP over HTTP as the communication channel between external businesses, and uses SOAP over JMS within the company's intranet. The use of SOAP over HTTP is for the sake of interoperability, since external businesses may be running on different platforms. Conversely, since a company controls applications running within its intranet, interoperability becomes less of an issue, and other features such as reliability may be deemed more important. The use of SOAP over JMS can compensate for the possible downtime of the systems running within the intranet, keeping data losses to a minimum.
WebSphere_5.0_Test_Environment
as the server name and select Test Environment from the WebSphere V5.0 folder. Click Finish:HelloWorld
and click OK. The WebSphere JMS Provider Options page should look like Figure 6: HelloWorld
as the name (this name must match the queue name you added to the JMS server in the previous step) and jms/HelloWorld
as the JNDI name. Click OK. HelloWorldQCF
as the name and jms/HelloWorldQCF
as the JNDI name. Click OK. WebServicesReplyQCF
as the name and jms/WebServicesReplyQCF
as the JNDI name. You cannot modify these names because they are fixed by the WebSphere Web service implementation. The WebSphere JMS Provider Options page should look like Figure 9: HelloWorldPort
as the name, select jms/HelloWorldQCF as the connection factory JNDI name, and jms/HelloWorld as the destination JNDI name. Click OK. This listener port will be used by a message-driven bean (MDB) to retrieve request messages from the defined queue. HelloWorldEJBRouter
as the project name and choose HelloWorldEJBEAR as the EAR project. Click Finish.getHelloWorld(java.lang.String)
method. Enter your name in the input text field and click Invoke. The result from the HelloWorld JMS Web service is displayed in the result pane: The use of the JMS transport is transparent to a Web service client, in other words, the client does not have to know the transport protocol that the Web service uses. When generating a client using WebSphere Studio, the tools will handle the selection of the JMS transport based on the information defined in the WSDL file. Figure 17 shows an XML fragment from the WSDL file describing the HelloWorld JMS Web service. The transport attribute of the WSDL binding element points to http://schemas.xml.soap.org/soap/jms
and the location of the endpoint address uses the JMS protocol. These are the signs that indicate the JMS transport protocol is being used.
SOAP over JMS offers an alternative messaging mechanism to SOAP over HTTP. While it is not yet standardized and hence may not be interoperable across platforms, SOAP over JMS offers more reliable and scalable messaging support than SOAP over HTTP. As JAX-RPC and JSR-109 become integral parts of the J2EE standard, enterprise messaging in Web services using SOAP over JMS will become well-established. This article has described the basics of JMS Web services and showed you how to develop a two-way request and response JMS Web service using WebSphere Studio V5.1.
Description | Name | Size |
---|---|---|
Code sample | HelloWorldEJB.zip ( HTTP | FTP ) | 3 KB |
聯(lián)系客服