...
Configure the JMS local transaction by defining the following parameter in the
<ESB HOME>/repository/conf/axis2/axis2.xml
file. By default the session is not transacted. In order to make it transacted, set the parameter to true.Code Block language html/xml <parameter name="transport.jms.SessionTransacted">true</parameter>
Once done, the JMS listener configuration for WSO2 MB in the axis2.xml file should be as follows:
Code Block language html/xml <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">repository/conf/jndi.properties</parameter> <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">TopicConnectionFactory</parameter> <parameter name="transport.jms.ConnectionFactoryType" locked="false">topic</parameter> <parameter name="transport.jms.SessionTransacted">true</parameter> <parameter name="transport.jms.SessionAcknowledgement" locked="true">CLIENT_ACKNOWLEDGE</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">repository/conf/jndi.properties</parameter> <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter> <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter> <parameter name="transport.jms.SessionTransacted">true</parameter> <parameter name="transport.jms.SessionAcknowledgement" locked="true">CLIENT_ACKNOWLEDGE</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">repository/conf/jndi.properties</parameter> <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter> <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter> <parameter name="transport.jms.SessionTransacted">true</parameter> <parameter name="transport.jms.SessionAcknowledgement" locked="true">CLIENT_ACKNOWLEDGE</parameter> </parameter> </transportReceiver>
Copy and paste the following configuration into the Synapse configuration in
$ESB_HOME/repository/deployment/server/synapse-configs/<node>/synapse.xml
.Code Block language html/xml <definitions xmlns="http://ws.apache.org/ns/synapse"> <proxy name="StockQuoteProxy" transports="jms" startOnLoad="true"> <target> <inSequence> <property name="OUT_ONLY" value="true"/> <callout serviceURL="http://localhost:9000/services/SimpleStockQuoteService"> <source type="envelope"/> <target key="placeOrder"/> </callout> <log level="custom"> <property name="Transaction Action" value="Committed"/> </log> </inSequence> <faultSequence> <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/> <log level="custom"> <property name="Transaction Action" value="Rollbacked"/> </log> </faultSequence> </target> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>application/xml</default> </rules> </parameter> </proxy> <sequence name="fault"> <log level="full"> <property name="MESSAGE" value="Executing default "fault" sequence"/> <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/> <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/> </log> <drop/> </sequence> <sequence name="main"> <log/> <drop/> </sequence> </definitions>
According to the above configuration, a message will be read from the JMS queue and will be sent to the
SimpleStockQuoteService
running on the Axis2 back-end server. If a failure occurs, the transaction will roll back.In the above configuration, the following property is set to true in the fault handler, in order to roll back the transaction when a failure occurs.
Code Block language html/xml <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
Tip If you are using a JMS Inbound endpoint for the transaction, set the scope of the
SET_ROLLBACK_ONLY
property todefault
as follows:<property name="SET_ROLLBACK_ONLY" scope="default" type="STRING" value="true"/>
- Deploy the back-end service
SimpleStockQuoteService
. For instructions on deploying sample back-end services, see Deploying sample back-end services. Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.
You now have a running ESB instance, WSO2 Message Broker instance and a sample back-end service to simulate the sample scenario. Now let's execute the JMS client.
Info Due to the asynchronous behavior of the Send Mediator, you cannot you use it with a http/https endpoint, but you can use it in asynchronous use cases, for example with another JMS as endpoint.
...
Testing the sample scenario
Successful scenario
In order to simulate the successful scenario, the message should mediate successfully.
When You can test the sample scenario as follows.
Successful scenario
If the message mediates successfully, you will view the output on the Axis2 server start-up console will be as follows:
The . Also, the ESB debug log will display an INFO message as follows, indicating that the transaction is committed.
Failure Scenario In order to simulate the failure scenario, you need to stop scenario
Stop the sample Axis2 Server and and execute the JMS client once again.
In again to simulate the failure scenario. In this scenario, the ESB debug log will display an INFO message as follows, indicating that the transaction is rolled back.
JMS distributed transactions
Anchor | ||||
---|---|---|---|---|
|
...
Info |
---|
Check if your application server provides a XAConnectionFactory when you look for the ConnectionFactory. |
...