This section describes how to configure the WSO2 ESB's JMS transport with ActiveMQ.
...
Follow the instructions below to set up and configure.
1. Download and set up Apache ActiveMQ. Instructions can be found in section Installation Prerequisites.
2. Follow the Getting Started and set up WSO2 ESB.
Info |
---|
ActiveMQ should be up and running before starting the ESB. |
3. Copy the following client libraries from the Anchor clientLibs clientLibs <AMQ_HOME>/lib
directory to the <
ESB_HOME>/repository/components/lib
directory.
ActiveMQ 5.8.0 and above
- 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
4. Next, configure transport listeners and senders in ESB.
AnchorListner Listner
Setting up the JMS Listener
Listner | |
Listner |
To enable the JMS transport listener, un-comment the following listener configuration related to ActiveMQ in <ESB_HOME>/repository/conf/axis2/axis2.xml file.
Code Block | ||
---|---|---|
| ||
<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener"> <parameter name="myTopicConnectionFactory" 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">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.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> <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> </transportReceiver> |
AnchorSender Sender
Setting up the JMS Sender
Sender | |
Sender |
To enable the JMS transport sender, un-comment the following configuration in <ESB_HOME>/repository/conf/axis2/axis2.xml file.
Code Block | ||
---|---|---|
| ||
<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/> |
Info |
---|
For details on the JMS configuration parameters used in the code segments above, see JMS Connection Factory Parameters. |
...
- Configure the ESB to work with one ActiveMQ broker as described above.
- Start another ActiveMQ instance.
Add another transport receiver to the <ESB_Home>/repository/conf/axis2/axis2.xml file as follows. Note that the name of the transport receiver is different to that of the transport receiver already entered. The port specified is
61617
.Code Block language xml <transportReceiver name="jms1" class="org.apache.axis2.transport.jms.JMSListener"> <parameter name="myTopicConnectionFactory" 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:61617</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.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61617</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.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61617</parameter> <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter> <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter> </parameter> </transportReceiver>
- Set up the JMS sender as explained in Setting up the JMS sender.
...
Configuring Redelivery ActiveMQ Queues
...
When WSO2 ESB is configured to consume messages from an ActiveMQ queue, you have the option to configure message re-delivery. This is useful when messages are unable to be processed by ESB due to failures.
- Enable the JMS listener as explained in Setting up the JMS listener.
Add the following JMS parameters into the proxy service configuration in WSO2 ESB:
Code Block language xml <parameter name="redeliveryPolicy.maximumRedeliveries">1</parameter> <parameter name="transport.jms.DestinationType">queue</parameter> <parameter name="transport.jms.SessionTransacted">true</parameter> <parameter name="transport.jms.Destination">JMStoHTTPStockQuoteProxy</parameter> <parameter name="redeliveryPolicy.redeliveryDelay">2000</parameter> <parameter name="transport.jms.CacheLevel">consumer</parameter>
Parameters
redeliveryPolicy.maximumRedeliveries
: Maximum number of retries for delivering the message. If set to -1 ActiveMQ will retry inifinitely.transport.jms.SessionTransacted
: When set totrue
, this enables the JMS session transaction for the proxy service.redeliveryPolicy.redeliveryDelay
: Delay time in milliseconds between retries.transport.jms
...
...
.CacheLevel
: This needs to be set toconsumer
for the ActiveMQ redelivery mechanism to work.
Add the following line in your fault sequence:
<property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
Info title SET_ROLLBACK_ONLY This parameter must be defined for ActiveMQ to redeliver the message.When ESB is unable to deliver a message to the back-end service due to an error, it will be routed to the fault sequence in the ESB configuration. When "SET_ROLLBACK_ONLY" property is set in the fault sequence, ESB informs ActiveMQ to redeliver the message.
Below is a sample proxy service configuration:
...
Code Block | ||
---|---|---|
| ||
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="JMStoHTTPStockQuoteProxy"
transports="jms"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="transactionID"
expression="get-property('MessageID')"
scope="default"/>
<property name="sourceMessageID"
expression="get-property('MessageID')"
scope="default"/>
<property name="proxyMessageID"
expression="get-property('MessageID')"
scope="default"/>
<log level="full">
<property name="transactionID" expression="get-property('transactionID')"/>
<property name="sourceMessageID" expression="get-property('sourceMessageID')"/>
<property name="MessageID" expression="get-property('proxyMessageID')"/>
</log>
<property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
<drop/>
</inSequence>
<faultSequence="jms_fault">
</target>
<parameter name="redeliveryPolicy.maximumRedeliveries">1</parameter>
<parameter name="transport.jms.DestinationType">queue</parameter>
<parameter name="transport.jms.SessionTransacted">true</parameter>
<parameter name="transport.jms.Destination">JMStoHTTPStockQuoteProxy</parameter>
<parameter name="redeliveryPolicy.redeliveryDelay">2000</parameter>
<parameter name="transport.jms.CacheLevel">consumer</parameter>
<description/>
</proxy> |