In addition to the Transaction Mediatorthe transaction mediator, WSO2 ESB also has support for supports JMS transaction. transactions. The JMS transport shipped with WSO2 ESB ships with a JMS transport which supports both local and distributed JMS distributed JMS transactions. In a JMS client, You can use local transactions to group message sends and receives. The JMS API Session interface provides commit and rollback methods that you can use in a JMS clientmessages received in a JMS queue. Local transactions are not supported for messages sent to a JMS queue.
...
Table of Contents | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Local Transaction
A local transaction represents a unit of work on a single connection to a data source managed by a resource manager. In JMS, we can use the JMS API to get a transacted session and call methods for commit or rollback for the relevant transaction objects. This is managed internal to a resource manager. There is no external transaction manager involved in the coordination of such transactions.
...
Code Block |
---|
<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 <property name="SET_ROLLBACK_ONLY" scope="default" type="STRING" value="true"/> |
JMS Distributed Transaction
...
The source of the mediator looks as shown below.
Code Block |
---|
public class MessageCounterMediator extends AbstractMediator {
private static int MESSAGE_COUNT = 0;
public boolean mediate(MessageContext synCtx) {
MESSAGE_COUNT++;
synCtx.setProperty("MESSAGE_COUNT", MESSAGE_COUNT);
return true;
}
}
|
ESB configuration is given below.
Code Block |
---|
<proxy name="StockQuoteProxy" transports="jms" startOnLoad="true">
<target>
<inSequence>
<class name="org.wso2.carbon.mediator.MessageCounterMediator"/>
<switch source="get-property('MESSAGE_COUNT')">
<case regex="1">
<property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
<log level="custom">
<property name="Transaction Action" value="Rollbacked"/>
</log>
</case>
<default>
<log level="custom">
<property name="Transaction Action" value="Committed"/>
</log>
<send>
<endpoint name="endpoint_urn_uuid_677F3EF4BC0AE1AF5B32399295906279-2025938318">
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</default>
</switch>
<property name="OUT_ONLY" value="true"/>
</inSequence>
</target>
<publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
<parameter name="transport.jms.ContentType">
<rules>
<jmsProperty>contentType</jmsProperty>
<default>application/xml</default>
</rules>
</parameter>
</proxy>
|
To start a local JMS transaction, define the following property in JMS transport Listner in axis2.xml
:
Code Block |
---|
<parameter name="transport.jms.SessionTransacted">true</parameter>
|
By default, the session is not transacted and if you want to use JMS local transaction, set the above parameter to true. Also note the following property in the failure case which will roll back the local transaction.
Code Block |
---|
<property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
|
...
5. Run the JMS client with following command:
Code Block |
---|
ant jmsclient -Djms_type=pox -Djms_dest=dynamicQueues/StockQuoteProxy -Djms_payload=MSFT
|
...
WSO2 ESB has the support for distributed JMS transaction. In this case, you can use the Transaction Mediator to manage multiple distributed resources. An ideal candidate for this category would be handling a JMS queue and a data base server using a single transaction. A sample configuration will be very similar to the distributed transaction example configuration given in the section on distributed transactions.
Excerpt | ||
---|---|---|
| ||
Description of JMS Transport Transaction in example in WSO2 ESB. |