...
There are two ways to implement transaction in WSO2 ESB as follows.
The ESB can control transactional behavior with a JMS queue and by simulating the Transactional Client EAI pattern. For information on Transactions in WSO2 ESB, refer to Transactions in the WSO2 ESB documentation.
...
Transactional Client EIP (Figure 1) | Transactional Client Example Scenario (Figure 2) |
---|---|
Transactional Producer | Proxy service inSequence |
Message | Simple Stock Quote Request |
Transactional Consumer | Simple Stock Quote Service |
...
- Download and install WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Getting Started Installation Guide in the WSO2 ESB documentation.
- Download and install a JMS server. We use ActiveMQ as the JMS provider in this example.
- In order to enable the JMS transport, edit
<ESB_HOME>/repository/conf/axis2/axis2.xml
as follows.
- Uncomment the Axis2 transport listener configuration for ActiveMQ as follows:
<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">...
Set the
transport.jms.SessionTransacted
parameter to true. After making this update, thetransportReceiver
section inaxis2.xml
should look as follows:Code Block language html/xml <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"> <parameter name="myQueueConnectionFactory" locked="false"> <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</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> <parameter name="default" locked="false"> <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</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> </transportReceiver>
- Uncomment the Axis2 transport sender configuration as follows:
<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>
- Uncomment the Axis2 transport listener configuration for ActiveMQ as follows:
- Copy the following ActiveMQ client jar files to the
<ESB_HOME>/repository/components/lib
directory. It allows the ESB to connect to the JMS provider.activemq-core-5.2.0.jar
geronimo-j2ee-management_1.0_spec-1.0.jar
- You need to add a custom mediator called
MessageCounterMediator
. Download theMessageCounterMediator
file and place it in the<ESB_HOME>/repository/components/lib
folder. To learn how to write custom mediators, refer toWriting Custom Mediator Implementations guide in the WSO2 ESB documentation. - Start the ActiveMQ (or equivalent JMS Server) and WSO2 ESB.
- Start the sample Axis2 server. For instructions, refer to the section Setting Up the ESB Samples Setup - Starting Sample Back-End Servicesthe Axis2 server in the WSO2 ESB documentation.
...
Start the ESB server and log into its management console UI (https:
//localhost:9443/carbon
). In the management console, navigate to the Main Menu, click Service Bus and then Source View menu and click Source View in the Service Bus section. Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.
Anchor | ||||
---|---|---|---|---|
|
...
- class [line 6 in ESB config] - A Custom mediator called
MessageCountMediator
is loaded. This mediator keeps track of the number of messages that pass through the sequence it calls by updating the value of a variable namedMESSAGE_COUNT
. - switch [line 10 in ESB config] - The Switch mediator checks the value of
MESSAGE_COUNT
. - case [line 11 in ESB config] - If the value of
MESSAGE_COUNT
is 1, the transaction is considered to have failed, and no message will be put on the send channel. - default [line 18 in ESB config] - The default action of the switch case flow control. This occurs when the
MESSAGE_COUNT
is anything but 1. The message is put on the send channel, and the transaction is considered a success.