This documentation is for WSO2 Message Broker version 2.0.0. View documentation for the latest release.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Apache AXIS2 support a JMS transport layer in addition to the existing HTTP transport. This allows Web service clients and servers to communicate via JMS queues and topics instead of HTTP connections. Both one-way and synchronous two-way requests are supported. 

The benefits of using JMS as an alternative to HTTP include the following:

  • Request and response messages are sent by way of reliable messaging.
  • One-way requests allow client and server to be more loosely-coupled (the server does not have to be active when the client sends the one-way request).
  • One-way requests can be sent to multiple servers simultaneously through the use of a topic.

If a web service is to be accessible on the JMS transport, then the corresponding WSDL document should include a JMS binding and a SOAP address which specifies a JMS endpoint URL string. A JMS binding is simply a wsdl:binding element which contains a wsdlsoap:binding element whose transport attribute ends in soap/jms, rather than the normal soap/http value. In addition to the JMS binding, a wsdl:port element which references the JMS binding should be included in the wsdl:service element within the WSDL document. This wsdl:port element should contain a wsdlsoap:address element whose location attribute specifies a JMS endpoint URL string.

You also need to decide on the names and types of JMS objects that your application will use. For example, you must decide whether your web service will receive its requests from a queue or a topic. You also must decide whether to use a secure destination (queue or topic). Finally, you will need to decide on the names for your destination, connection factory, and listener port.   The following list provides an example of the names that might be used for the sample MessageReceiveService web service:

 

  
QueueMessageReceiveService, JNDI name: MessageReceiveService
QueueConnectionFactoryamqp://admin:admin@clientid/carbon?brokerlist='tcp://localhost:5672' JNDI name: QueueConnectionFactory

Creating a Simple Service

Following java class with its two operations are hosted in Axis2 server.

/*
*  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/
 
public class MessageReceiveService {
    public void receive(String message) {
        System.out.println("Got the message ==> " + message);
    }
    public String echo(String message) {
        System.out.println("Got the message ==> " + message);
        return message;
    }
}

Axi2 Configurations

axi2.xml file, which configures the axis2 server on which above service is hosted, should be enabled with JMS transport.

<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
	<parameter name="default" locked="false">
		<parameter name="java.naming.factory.initial" locked="false">org.wso2.andes.jndi.PropertiesFileInitialContextFactory</parameter>
		<parameter name="java.naming.provider.url" locked="false">conf/jndi.properties</parameter>
		<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
		<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
	</parameter>
</transportReceiver>
<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>

 

Start Axis2 Server

Axis2 server is started with above configurations, hosting the above service.

private AxisServer axisServer;
public void start(){
	try {
	    ConfigurationContext configurationContext =
		    ConfigurationContextFactory.createConfigurationContextFromFileSystem(null,"conf/axis2.xml");
	    this.axisServer = new AxisServer();
	    this.axisServer.setConfigurationContext(configurationContext);
	    this.axisServer.deployService(MessageReceiveService.class.getName());
	    try {
		Thread.sleep(2000);
	    } catch (InterruptedException e) {
	    }
	} catch (AxisFault axisFault) {
	    axisFault.printStackTrace();
	} catch (Exception e) {
	    e.printStackTrace();
	}
}

 

 

  • No labels