A JMS synchronous invocation takes place when a JMS producer receives a response to a JMS request produced by it when invoked. WSO2 ESB The ESB Profile of WSO2 Enterprise Integrator (WSO2 EI) uses an internal JMS correlation ID to correlate the request and the response. See JMS Request/Reply Example for more information.
JMS synchronous invocations are further explained in the following use case.
Use case
When the proxy service named SMSSenderProxy
receives an HTTP request, it publishes that request in a JMS queue named SMSStore
. Another proxy service named SMSForwardProxy
subscribes to messages published in this queue and forwards them to a back-end service named SimpleStockQuoteService
. When this back-end service returns an HTTP response, internal ESB logic is used to save that message as a JMS message in a JMS queue named SMSReceiveNotification
. Then this response is taken from the SMSReceiveNotification
queue and delivered to the client as an HTTP message using internal ESB logic.
The following sub sections explain how to execute this use case. WSO2 Here, the Message Broker is Profile of WSO2 EI is used as the JMS broker.
Table of Contents | ||||
---|---|---|---|---|
|
Prerequisites
Before executing this use case, the following steps need to be carried out. See Integrating WSO2 ESB in MB Documentation for detailed instructions.
- WSO2 MB should be installed and set up. See Setting up WSO2 Message Broker.
WSO2 ESB should installed and set up. See Setting up WSO2 ESB. Specific entries that are required to be added to the
<ESB_HOME>/repository/conf/jndi.properties
file for this use case are as follows.
Item Value Queue queue.SMSStore=SMSStore
Queue queue.SMSReceiveNotificationStore=SMSReceiveNotificationStore
Connection Factory Install WSO2 Enterprise Integrator. For information on how you can install, see the Installing the Product.- Deploy the sample back-end service.
In this example, the
SimpleStockQuoteService
serves as the back-end service and receives the message from theSMSForwardProxy
proxy service via the JMS transport. The response sent by theSimpleStockQuoteService
is published in theSMSReceiveNotificationStore
queue that is set as the value of thetransport.jms.ReplyDestination
parameter of theSMSSenderProxy
proxy service. This allows theSMSSenderProx
y to pick the response and deliver it to the client. Follow the steps below to build and deploy theSimpleStockQuoteService
:- Open a command prompt (or a shell in Linux) and go to the
<EI_HOME>/samples/axis2Server/src/SimpleStockQuoteService
directory. Run
ant
.
- Open a command prompt (or a shell in Linux) and go to the
- Follow the steps below to enable the JMS transport of the ESB Profile to communicate with the Message Broker profile:
Edit the
<EI_HOME>/conf/axis2/axis2.xml
file, find the commented<transport receiver>
block and uncomment it as follows:Code Block language html/xml <!--Uncomment this and configure as appropriate for JMS transport support with WSO2 MB 2.x.x --> <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"> <parameter name="myTopicConnectionFactory" 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">TopicConnectionFactory</parameter> <parameter name="transport.jms.ConnectionFactoryType" locked="false">topic</parameter> </parameter> <parameter name="myQueueConnectionFactory" 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> <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>
Uncomment the following
<transport sender>
block for JMS in the same file:Code Block language html/xml <!-- uncomment this and configure to use connection pools for sending messages--> <transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>
Info For more information on the JMS configuration parameters used in the code segments above, see JMS Connection Factory Parameters.
Open the
<EI_HOME>/conf/jndi.properties
file and update the connection factories and queues as follows:Code Block # register some connection factories # connectionfactory.[jndiname] = [ConnectionURL] connectionfactory.QueueConnectionFactory = amqp://admin:admin@clientID/carbon?brokerlist='tcp://localhost:
5675' # register some queues in JNDI using the form # queue.[jndiName] = [physicalName] queue.SMSStore=SMSStore queue.SMSReceiveNotificationStore=SMSReceiveNotificationStore
- Copy the following JARs from the
<EI_HOME>/wso2/broker/client-lib
folder to the<EI_HOME>/lib
folder.andes-client-3.2.19.jar
geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
org.wso2.securevault-1.0.0-wso2v2.jar
- Start the Message Broker Profile. For information on how to start the Message Broker Profile, see Starting the Message Broker Profile.
- Start the ESB Profile. For information on how to start the ESB Profile, see Starting the ESB Profile.
Configuring the JMS publisher
Configure a proxy service named SMSSenderProxy
as shown below to accept messages sent via the HTTP transport, and to place those messages in the SMSStore
queue in WSO2 MB.follows:
Code Block | ||||
---|---|---|---|---|
| ||||
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SMSSenderProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="transport.jms.ContentTypeProperty"
value="Content-Type"
scope="axis2"/>
</inSequence>
<outSequence>
<property name="TRANSPORT_HEADERS" scope="axis2" action="remove"/>
<send/>
</outSequence>
<endpoint>
<address uri="jms:/SMSStore?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&java.naming.provider.url=repository/conf/jndi.properties&transport.jms.DestinationType=queue&transport.jms.ReplyDestination=SMSReceiveNotificationStore"/>
</endpoint>
</target>
<description/>
</proxy> |
This proxy service accepts messages sent via the HTTP transport, and stores the messages in the SMSStore
queue in the Message Broker Profile of WSO2 EI.
The endpoint of this proxy service uses the following properties to map the proxy service with WSO2 MB.the Message Broker Profile:
Property | Value for this use case | Description |
---|---|---|
address uri |
| The destination in which the request received by the proxy service is stored. |
java.naming.factory.initial |
|
The initial context factory to use. |
|
|
java.naming.provider.url |
| The location of the JNDI service provider. | |
transport.jms.DestinationType | queue | The destination type of the JMS message that will be generated by the proxy service. |
transport.jms.ReplyDestination |
| The destination in which the response generated by the back-end service is stored. |
Since this is a two-way invocation, the OUT_ONLY property is not set in the In sequence.
...
Configure a proxy service named SMSForwardProxy
to consume messages from the SMSStore
queue in WSO2 MB of the Message Broker Profile, and forward them the messages to the back-end service.
Code Block | ||
---|---|---|
| ||
<proxy xmlns="http://ws.apache.org/ns/synapse" name="SMSForwardProxy" transports="jms" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </inSequence> <outSequence> <send/> </outSequence> </target> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>text/xml</default> </rules> </parameter> <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter> <parameter name="transport.jms.DestinationType">queue</parameter> <parameter name="transport.jms.Destination">SMSStore</parameter> <description/> </proxy> |
The transport.jms.ConnectionFactory
, transport.jms.DestinationType
parameter and the transport.jms.Destination properties
parameter map this the proxy service to the SMSStore
queue.
The SimpleStockQuoteService
sample shipped with WSO2 ESB EI is used as the back-end service in this example. To invoke this service, the address URI of this proxy service is defined as http://localhost:9000/services/SimpleStockQuoteServic
e.
Start the back-end service
In this example, the SimpleStockQuoteService
serving as the back-end receives the message from the SMSForwardProxy
proxy service via the JMS transport. The response is sent by SimpleStockQuoteService
is published in the SMSReceiveNotificationStore
queue which was set as the value for the transport.jms.ReplyDestination
parameter of the SMSSenderProxy
proxy service. This allows the SMSSenderProx
y to pick the response and deliver it to the client.
The back-end service is started as follows.
...
Starting the Axis2 server
Follow the steps below to start the Axis2 server:
- Open a command prompt (or a shell in Linux) and go to the
<EI_HOME>/samples/axis2Server
directory.
For directory. - Execute one of the following commands
- On Windows:
axis2server.bat
- On Linux/Solaris:
./axis2server.sh
- On Windows:
- Execute the
ant
command from<ESB_HOME>/samples/axis2Server/src/SimpleStockQuoteService
directory.
...
Invoking the JMS publisher
Execute the following command from the <ESBthe <EI_HOME>/samplesamples/axis2Client
directory to directory to invoke the SMSSenderProxy
proxy service that you defined as the JMS publisher.:
Code Block |
---|
ant stockquote -Daddurl=http://localhost:8280/services/SMSSenderProxy -Dsymbol=IBM |
Analyzing the output
Analyze the output on the Axis2 server console as well as the output on the client console to understand how a JMS producer can receive a response to a JMS request produced by it.
You will see the following on the Axis2 server console:
Code Block |
---|
Fri Dec 08 11:19:29 IST 2017 samples.services.SimpleStockQuoteService :: Generating quote for : IBM |
You will get see the following response .on the client console:
Code Block |
---|
Standard :: Stock price = $149$162.4366923344766204696182786148 |