Publish WSO2 logs into JMS Queue through Log appender

Asara kumarasena
3 min readFeb 12, 2022

--

👉 If you need to Send WSO2 logs into JMS queue through a log appender, you can find the steps and information from this article 😀.I’m using WSO2 Enterprise Integrator 6.6 product and ActiveMQ 5.15.6 version for this tutorial.

  1. Download and Install the ActiveMQ

First, we need to download and install the ActiveMQ into our local machine.You can find the relavant ActiveMQ 5.15.6 version from here.

2. Configure ActiveMQ

Copy the following client libraries from the <ACTIVEMQ_HOME>/lib directory to the <EI_HOME>/lib directory

  • activemq-broker-5.15.6.jar
  • activemq-client-5.15.6.jar
  • activemq-kahadb-store-5.15.6.jar
  • geronimo-jms_1.1_spec-1.1.1.jar
  • geronimo-j2ee-management_1.1_spec-1.0.1.jar
  • geronimo-jta_1.0.1B_spec-1.0.1.jar
  • hawtbuf-1.11.jar
  • Slf4j-api-1.7.25.jar
  • activeio-core-3.1.4.jar (available in the <ACTIVEMQ_HOME>/lib/optional directory)

3. Apply Security to ActiveMQ

There are four common security concepts that are implemented in Apache ActiveMQ and we are going to use the Basic Authentication between the ActiveMQ JMS and WSO2 EI. You can find more information regarding the security scenarios from the official wso2 Website.

ActiveMQ comes with an authentication plugin and add simpleAuthenticationPlugin plugin to the <ActiveMQ_HOME>/conf/activemq.xml file as below to enable the authentication.

<plugins><!-- Configure authentication; Username, passwords and groups -->   <simpleAuthenticationPlugin>     <users>         <authenticationUser              username="asara"              password="password"              groups="admins,publishers,consumers"/>     </users>   </simpleAuthenticationPlugin></plugins>

Then, you have to configure the <ActiveMQ_HOME>/conf/credentials.properties file as well by providing the above username and password to access the web console.

# Defines credentials that will be used by components (like web console) to access the brokeractivemq.username=asara
activemq.password=password

4. Setting up the JMS sender

Since we are going to send the logs to a JMS Queue, we have to enable the JMS tansport sender by un-commenting the following configuration in <EI_HOME>/conf/axis2/axis2.xml file.

<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>

5. Start the ActiveMQ server

Go to the <ACTIVEMQ_HOME>/bin directory and use the below command to start the ActiveMQ server.

./activemq console

By default ActiveMQ WebConsole available at http://0.0.0.0:8161/ URL and create a Queue as you wish. In here I created a queue as MyQueue

6. Configure the Log4j2.properties

We should create a new log appender and we define the connection details of the queue in here. I’m creating a appender as CARBON_LOGJMS. Go to the <EI_HOME>/conf directory and add the below section in the log4j2.properties file.

# CARBON_LOGJMS is the equivalent of the logfile but sends the information to a JMS queueappender.CARBON_LOGJMS.name = CARBON_LOGJMS
appender.CARBON_LOGJMS.layout.type = JSONLayout
appender.CARBON_LOGJMS.type = JMS
appender.CARBON_LOGJMS.filter.threshold.type = ThresholdFilter
appender.CARBON_LOGJMS.filter.threshold.level = INFO
appender.CARBON_LOGJMS.factoryBindingName = ConnectionFactory
appender.CARBON_LOGJMS.factoryName = org.apache.activemq.jndi.ActiveMQInitialContextFactory
appender.CARBON_LOGJMS.providerURL = tcp://asara:61616
appender.CARBON_LOGJMS.destinationBindingName = dynamicQueues/MyQueue
appender.CARBON_LOGJMS.userName = asara
appender.CARBON_LOGJMS.password=password

Then we have to add newly created appender into the appenders section as below.

# list of all appenders

appenders = CARBON_LOGJMS,CARBON_CONSOLE, CARBON_LOGFILE, AUDIT_LOGFILE, ATOMIKOS_LOGFILE, CARBON_TRACE_LOGFILE, osgi, SERVICE_LOGFILE, API_LOGFILE, ERROR_LOGFILE

Finally, we must define which information should be sent to the JMS queue.To achieve that you can create loggers as below.

logger.org-apache-synapse.name=org.apache.synapse
logger.org-apache-synapse.level=INFO
logger.org-apache-synapse.appenderRef.CARBON_LOGJMS.ref = CARBON_LOGJMS

logger.org-wso2-carbon.name=org.wso2.carbon
logger.org-wso2-carbon.level=INFO
logger.org-wso2-carbon.appenderRef.CARBON_LOGJMS.ref = CARBON_LOGJMS

7. Start EI server.

Monitor the created queue when starting the EI server and all the starting logs are getting written in to that.

If you don’t need to add plain text passwords in the log4j2.properties file, you can define a system property or Environment variable as below to feed the sensitive data to the log4j2.properties file.

appender.CARBON_LOGJMS.password=${sys:pwd}               ORappender.CARBON_LOGJMS.password=${env:pwd}

Hope this will be helpful to the beginners to implement such kind of scenarios👏🤓

--

--

Asara kumarasena
Asara kumarasena

Written by Asara kumarasena

Graduate Student @Wayne State University | Former Software Engineer @WSO2

No responses yet