Objective: Demonstrate
Table of Contents |
---|
Introduction
This sample demonstrates how one way message bridging from JMS to HTTP and replying with a HTTP 202 Accepted response.
Prerequisites
...
can be done using the inbound JMS endpoint.
Prerequisites
- Download and set up Apache ActiveMQ. Instructions can be found in section Installation Prerequisites.
Copy the following client libraries from the
ActiveMQ 5.8.0 and above<AMQ_HOME>/lib
directory to the<
ESB_HOME>/repository/components/lib
directory.activemq-broker-5.8.0.jar
activemq-client-5.8.0.jar
geronimo-jms_1.1_spec-1.1.1.jar
geronimo-j2ee-management_1.1_spec-1.0.1.jar
hawtbuf-1.9.jar
Earlier version of ActiveMQ
activemq-core-5.5.1.jar
geronimo-j2ee-management_1.0_spec-1.0.jar
geronimo-jms_1.1_spec-1.1.1.jar
Building the sample
The XML configuration for this sample is as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
<definitions xmlns="http://ws.apache.org/ns/synapse"> <registry <proxy nameprovider="JMStoHTTPStockQuoteProxy" transports="jms"org.wso2.carbon.mediation.registry.WSO2Registry"> <parameter <target>name="cachableDuration">15000</parameter> </registry> <taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"> <inSequence> <parameter name="cachableDuration">15000</parameter> </taskManager> <property action="set<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse" name="OUTjms_ONLYinbound" valuesequence="truerequest"/> onError="fault" protocol="jms" suspend="false"> <parameters> </inSequence> <parameter name="interval">1000</parameter> <endpoint> <parameter name="transport.jms.Destination">ordersQueue</parameter> <parameter <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>name="transport.jms.CacheLevel">1</parameter> </endpoint><parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter> <outSequence> <send/><parameter name="sequential">true</parameter> </outSequence><parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> </target> <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/><parameter name="java.naming.provider.url">tcp://localhost:61616</parameter> </proxy> <proxy<parameter name="OneWayProxy" transports="http">transport.jms.SessionAcknowledgement">AUTO_ACKNOWLEDGE</parameter> <target> <parameter name="transport.jms.SessionTransacted">false</parameter> <parameter <inSequence>name="transport.jms.ConnectionFactoryType">queue</parameter> </parameters> </inboundEndpoint> <sequence <log levelname="request" onError="fullfault"/> <call> </inSequence> <endpoint> <address<address format="soap12" uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </call> <outSequence> <send <drop/> </outSequence> </target> <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/> </proxy> </definitions> |
This example invokes the one-way placeOrder
operation on the SimpleStockQuoteService
using the Axis2 ServiceClient.fireAndForget()
API at the client. To test this, use ant -Dmode=placeorder...
and you will notice the one way JMS message flowing through ESB into the sample Axis2 server instance over HTTP, and Axis2 acknowledging it with a HTTP 202 Accepted response.
Code Block |
---|
ant stockquote -Dmode=placeorder -Dtrpurl="jms:/JMStoHTTPStockQuoteProxy?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.ContentTypeProperty=Content-Type&transport.jms.DestinationType=queue"
|
Code Block |
---|
SimpleStockQuoteService :: Accepted order for : 7482 stocks of IBM at $ 169.27205579038733
|
The second example shows how ESB can be made to respond with a HTTP 202 Accepted response to a request received. The Proxy Service simply logs the message received and acknowledges it. On the ESB console you could see the logged message, and if TCPMon was used at the client, you would see the 202 Accepted response sent back to the client from ESB.
Code Block |
---|
ant stockquote -Dmode=placeorder -Dtrpurl=http://localhost:8280/services/OneWayProxy
|
Code Block |
---|
HTTP/1.1 202 Accepted Content-Type: text/xml; charset=UTF-8 Host: 127.0.0.1 SOAPAction: "urn:placeOrder" Date: Sun, 06 May 2007 17:20:19 GMT Server: Synapse-HttpComponents-NIO Transfer-Encoding: chunked 0 sequence> </definitions> |
This configuration file synapse_sample_901.xml
is available in the <ESB_HOME>/repository/samples
directory.
To build the sample
Start the ESB with the sample 901 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.
The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.
Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.
Executing the sample
To execute the sample client
- Log on to the ActiveMQ console using the http://localhost:8161/admin url.
- Browse the queue
ordersQueue
listening via the above endpoint. Add a new message with the following content to the queue:
Code Block language html/xml <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing"> <soapenv:Body> <m0:getQuote xmlns:m0="http://services.samples"> <m0:request> <m0:symbol>IBM</m0:symbol> </m0:request> </m0:getQuote> </soapenv:Body> </soapenv:Envelope>
Analyzing the output
You will see that the JMS endpoint gets the message from the queue and sends it to the stock quote service.
Excerpt | ||
---|---|---|
| ||
Example of bridging from JMS to HTTP and replying with a 202 Accepted response in WSO2 ESBusing inbound JMS protocol. |