How to Connect Apache Artemis with WSO2 EI

Nipuna Dilhara
4 min readMar 22, 2020

--

Here we are going to talk about connecting the Apache ActiveMQ Artemis with the Wso2 EI.

We will be creating to create a JMS Inbound Endpoint at the EI which will listen to an Artemis JMS Queue. Then the Queue can be used to publish messages to the Inbound Endpoint and do whatever you want with it.

If you are unfamiliar with the Artemis broker, it’s the time to read my previous blog titled ‘Apache ActiveMQ Artemis 101’. It will walk you through basic details about this broker such as:

  • What it Apache Artemis
  • How to create a broker instance and make it up and running.

So don’t be LAZY. This post won’t go anywhere till you read that. So please feel free to take your time.

OK. Let’s start by configuring JMS listeners and Senders.

Step 1: Add the following transport receiver configuration to the <EI_HOME>/conf/axis2/axis2.xml file.

<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.artemis.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.artemis.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.artemis.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>

Step 2: Add the below transport sender configuration to the same axis2.xml file.

<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender">    <parameter name="myTopicConnectionFactory" locked="false">
<parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.artemis.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.artemis.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.artemis.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>
</transportSender>

Step3: Download the artemis-jms-client-all-2.6.1.jar file and copy it to the <EI_HOME>/lib directory.

If there are any existing Apache ActiveMQ client jar files in that directory, make sure to remove them.

Step4: Add the Inbound Endpoint to the EI.

Up to this point, we have completed all the necessary configurations for the EI to connect with the Artemis broker. Now let’s create an Inbound Endpoint which will listen to an Artemis JMS queue.

In order to do that, save the following configuration as an XML file and copy to <EI_HOME>/repository/deployment/server/synapse-configs/default/inbound-endpoints folder.

<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"
name="testInbound"
sequence="testSeq"
onError="fault"
protocol="jms"
suspend="false">
<parameters>
<parameter name="interval">5</parameter>
<parameter name="sequential">true</parameter>
<parameter name="coordination">true</parameter>
<parameter name="java.naming.factory.initial">org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory</parameter>
<parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType">queue</parameter>
<parameter name="transport.jms.Destination">TestQueue</parameter>
<parameter name="transport.jms.SessionAcknowledgement">AUTO_ACKNOWLEDGE</parameter>
<parameter name="transport.jms.CacheLevel">3</parameter>
<parameter name="transport.jms.SubscriptionDurable">false</parameter>
<parameter name="transport.jms.SharedSubscription">false</parameter>
<parameter name="transport.jms.ResetConnectionOnPollingSuspension">false</parameter>
</parameters>
</inboundEndpoint>

This is designed to create a queue called TestQueue at the Artemis broker.

The above testInbound will listen to the TestQueue. When a message is published to the TestQueue, the testInbound will read the message and then forwarded it to a synapse sequence called testSeq.

<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"
name="testInbound"
sequence="testSeq"
...>

Then let’s create the testSeq too.

Save the below configuration too as an XML file and copy to <EI_HOME>/repository/deployment/server/synapse-configs/default/sequences folder.

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="testSeq">
<log level="custom">
<property name="testLog" value="message is received by the target sequence"/>
</log>
<drop/>
</sequence>

Step5: Start the Artemis server by running the following command.

$ ./artemis run

If you didn’t read my other post on Artemis basics [1] (even after I asked you to read it politely) and now you feel like you have lost, then maybe it’s the right time to read it.

Step 5: Start the EI server by navigating to the <EI_HOME>/bin and executing the command:

./integrator.sh (on Linux/OSX) or integrator.bat (on Windows)

I only tested the setup with Linux and it should work with Mac too. If you are using Windows, then you are on your own.

Step 6: Log into the Artemis management console and navigate to the Queues.

If all the things are done perfectly, you will see the TestQueue has been created at the Artemis broker.

Didn’t you see it? Check again.

If you want to create this queue under a different name, then change the below Inbound Endpoint configuration.

<parameter name="transport.jms.Destination">TestQueue</parameter>

If this property is not set, then the queue will be created using the same name as the Inbound Endpoint.

OK. That’s it then.

See you again with the next part of the Artemis series on connecting Artemis broker and WSO2 EI over SSL.

References

[1] https://medium.com/@nipunadilhara/apache-activemq-artemis-101-4821582c6670

[2] https://docs.wso2.com/display/EI650/Configure+with+Apache+Artemis

--

--