September 10, 2015

JMS Queue Clustering on JBOSS EAP Servers

JBoss or EAP Clustering is a major reason why the JBoss Application Server is a true enterprise-class application server. With its fail-over, load-balancing, and distributed deployment features, JBoss Clustering provides the means to develop large, scalable, and robust applications.

Within this article, we will showcase the clustering of two JMS queues with the JBOSS application server. We are going to distribute our JMS queue on two JBOSS servers. We will deploy a Test application on both servers, which will provide a way to push messages into their respective queue. Additionally, we will push messages into one JBoss server, which will be distributed between both JMS queues on their respective servers. This kind of topology can be used to achieve scalable and highly available enterprise applications.

Technology Stack & Environment

  • Java 6.0 or later
  • JBoss EAP 6.4 Beta (We would recommend using any available released version of the JBoss EAP Server)
  • JMS/HornetQ
  • Ubuntu OS

In our scenario, we are using the EAP 6.4 Beta version, which can be downloaded from the official JBoss website. The focus will be on making a clustering between two different Ubuntu machines.

Prerequisite

Before setting up the clustering, we need to have a basic infrastructure:

  • Prepare 2 Ubuntu machines or VMs
  • Install Java on both Ubuntu machines

To install Java, use the following commands:

§  sudo add-apt-repository ppa:webupd8team/java
§  sudo apt-get update

The JBoss EAP server provides two built-in cluster configuration files, named standalone-ha.xml and standalone-full-ha.xml, with the latter including CORBA support. We can find these files inside the folder accessed through: jboss-eap-6.4.0.Beta/jboss-eap-6.4/standalone/configuration.

Steps to Configure the JBoss EAP Server for Clustering on Two Different Machines/Servers

The following steps should be used to configure the JBoss cluster onto two Ubuntu machines called Machine A (IP address 10.0.2.50) and Machine B (IP address 10.0.2.51).

  1. Take the standalone-full-ha.xml configuration file, which is placed inside the jboss-eap-6.4.0.Beta/jboss-eap-6.4/standalone/configuration folder on Ubuntu machine A
  2. Find tag <transport type=”TCP” socket-binding=”jgroups-tcp”/> and add the following configuration.
    <protocol type="TCPPING">
                    	<property name="initial_hosts">
                        	10.0.2.50[7600], 10.0.2.51[7600]
                    	</property>
                    	<property name="num_initial_members">
                        	2
                    	</property>
                    	<property name="port_range">
                            0
                    	</property>
                    	<property name="timeout">
                        	2000
                    	</property>
                </protocol>

    This addition should make the configuration look like the following screenshot.JMS Queue Clustering The port number 7600 is used for socket-binding fir the TCPPING protocol; we can change this port by modifying the port number of the <socket-binding name=”jgroupd-tcp”port=”7600″/> property.

  3. Find the <hornetq-server> tag in our configuration file and add the following element into it: <cluster-password>any-password-except</cluster-password>. If that tag attribute is already present, make sure to create some kind of password for the servers.
  4. We need to add the JMS queue. To do this, we need to find <jms-destinations> in our configuration file and add the following JMS queue properties
    <jms-destinations>
                	<jms-queue name="testQueue2">
                        	<entry name="jms/queue/testQueue2"/>
                        	<entry name="java:jboss/exported/jms/queue/testQueue2"/>
                  	</jms-queue>
    </jms-destinations>
  5. Repeat steps 1-4 for the Ubuntu Machine B

Commands to Start the JBoss-EAP Server

Once we finish with the configurations, we can now start our servers. To do this, we first navigate to the jboss-eap-6.4.0.Beta/jboss-eap-6.4/bin folder on Server A and execute the following command at the terminal

./standalone.sh -c standalone-full-ha.xml -b=10.0.2.50 -bmanagement=10.0.2.50 -Djboss.node.name=serverA

Similarly, to start Server B, we navigate to the jboss-eap-6.4.0.Beta/jboss-eap-6.4/bin folder and execute the followign command at the terminal

./standalone.sh -c standalone-full-ha.xml -b=10.0.2.51 -bmanagement=10.0.2.51 -Djboss.node.name=serverB

Notes:

  • -c refers to the server configuration file to be used
  • -b is for the binding address
  • -bmanagement is for the admin console

Deploying the Test Application

The next step is to test the cluster. To do this, first download the test application here. This application pushes test data into the previously configured JMS queue named “testQueue2.” The messages sent to this queue will be distributed between both nodes of the cluster.

The downloaded application file, which is a war configuration, should be deployed on both servers. There are two ways to deploy any war/ear file on a JBoss EAP server:

  1. Directly put the war/ear file inside the deployment directory of the JBoss
  2. Use the admin console of the JBoss

In this example, we are going to use the second way to deploy our application to test the JBoss clustering.

First, we follow step 6.2.2 (“Creating a Management User in EAP 6”) on this guide to set-up a user account on the JBoss server, which will then allow us to open the admin console.

Because our servers are already running, we can visit URL 10.0.2.50:9990 and 10.0.2.51:9990 in the browser. Once we reach those addresses, a pop-up window will appear and ask us to enter a username and password. After successfully logging in, we should see the following admin screen.

JBoss Queue Clustering

The purpose of the deployed application is to push messages into the testQueue2. Because both JBoss servers are running in a clustered environment, the messages will be distributed onto both servers in a round robin fashion. To deploy the application, visit Deployments > Add and browse the downloaded war file.

After the application successfully deploys, the following screen should appear:

JBoss Queue Clustering

Testing the JMS Queue Clustering

After the test application has been successfully deployed onto both servers, we can begin to test our configured clustering.

To test the clustering, we need to push some messages into our JMS queue. We begin by visiting the URL 10.0.0.50:8080/DemoJSM/MessageServlet?count=2, which will push two message into the JMS queue and allow us to see all messages distributed across both servers through the admin console.

To view the JMS queue detail, go to Runtime > JMS Destinations and click on “testQueue2.” Visible in Queue Metrics section for both servers’ admin console should be 1 message on each server, because we have only pushed 2 messages through with our test application.

We can also test the clustering with a higher message count, and would be able to see the messages being distributed on both servers’ JMS HornetQ queue.

Recommendations:

  1. AWS or Azure Cloud can be helpful in providing required infrastructure for practice purpose, and are both free to use
  2. JBoss EAP 6.4.0.GA should be used in a production environment