DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Get Cell Data From an Excel Spreadsheet Using APIs in Java
  • 8 Strategies To Accelerate Web Portal Development
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  • Managed MQTT Broker Comparison — Console/Dashboard Features

Trending

  • Idempotency Under Concurrency: Why Your Application Check Isn't the Last Line of Defense
  • Mistaking Code Production for Engineering Progress: AI Productivity Myths Part 1
  • Building a Practical Cloud-Native Golden Path: A Guide to Kubernetes-Based Service Delivery, Self-Service, and Developer-Friendly Defaults
  • Detection and Response Did Its Job. Now Someone Has to Actually Fix It.

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

ActiveMQ: Configuring Multiple Instances of the Web Console

By 
Jason Sherman
·
Jan. 20, 13 · Interview
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
11.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in
When configuring multiple instances of ActiveMQ brokers in master slave configurations it may be useful to configure the web console for each broker in a single Jetty instance.   This will allow you to use a single URL to access each of the brokers by simply changing the URL context.

We will configure the ActiveMQ brokers using two master slave pairs as follows:

AMQ1M - AMQ1 Master
AMQ1S - AMQ1 Slave

The web console to service these brokers will be configured as: http://localhost:8080/amq1

In the event that AMQ1M should fail, this url will then failover to AMQ1S.

AMQ2M - AMQ2 Master
AMQ2S - AMQ2 Slave

The web console to service these brokers will be configured as: http://localhost:8080/amq2

In the event that AMQ2M should fail, this url will then failover to AMQ2S.

This configuration allows the URL to be descriptive by identifying the brokers it is servicing while keeping port configuration to a minimum by utilizing a single Jetty instance.

So with the concept out of the way lets look at the configuration that will make this happen.

Note: In this example I will be using the FuseSource distribution of ActiveMQ.  Below is a list of binaries used to setup this example.  However, the instructions provided should work with both the Apache and FuseSource distributions.

  • apache-activemq-5.5.1-fuse-01-13
  • activemq-web-console-5.5.1-fuse-01-13.war
  • jetty-distribution-7.5.4.v20111024.zip

Step 1.
Grab a Jetty distribution from the Eclipse Jetty download site.  Once downloaded, extract the zip or tar.

Step 2.
Add the activemq-all-x.x.x-fuse-xx-xx.jar to the Jetty /lib directory.

Step 3.
Down the ActiveMQ web console war.  This can be obtained via the FuseSource repo: activemq-web-console.  Explode the activemq-web-console-x.x.x-fuse-xx-xx.war to Jetty's web apps directory in a web context named amq1.  Repeat this, and create web context amq2.  Once the war is exploded we will need to add some JNDI configuration to each webapp's web descriptor (WEB-INF/web.xml).  At this point you should have a directory structure that resembles the following:

webapps
     |_amq1
     |_amq2

Step 5.
For each of the web application's (amq1 and amq2) web descriptor files (WEB-INF/web.xml) we are going to add the following JNDI configuration:
<!--  ========================================================== -->
<!--  JNDI Config -->
<!--  ========================================================== -->

<resource-ref>
        <res-ref-name>jms/connectionFactory</res-ref-name>
        <res-type>javax.jms.ConnectionFactory</res-type>
        <res-auth>Container</res-auth>
</resource-ref>

<resource-ref>
          <res-ref-name>jmx/url</res-ref-name>
          <res-type>java.lang.String</res-type>
          <res-auth>Container</res-auth>
</resource-ref>
Step 6.
The last piece of configuration we need is to create jetty-env.xml files for each of the web applications.  The jetty-env.xml is used to configure the JNDI resources specific to the application and the file will reside in the WEB-INF/ directory.  In each file, the ConnectionFactory and JMX URL will be specified.

For amq1 the jetty-env.xml will be configured as follows:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="amq1" class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="connectionFactory" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg><Ref id="amq1"/></Arg>
        <Arg>jms/connectionFactory</Arg>
        <Arg>
            <New class="org.apache.activemq.ActiveMQConnectionFactory">
                <Arg>failover:(tcp://localhost:61616,tcp://localhost:62616)</Arg>
            </New>
        </Arg>
    </New>
    <New id="url" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg><Ref id="amq1"/></Arg>
        <Arg>jmx/url</Arg>
        <Arg>
            <New class="java.lang.String">
                <Arg>service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi,service:jmx:rmi:///jndi/rmi://localhost:1299/jmxrmi</Arg>
            </New>
        </Arg>
    </New>
</Configure>
For amq2 the jetty-env.xml will be configured as follows:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="amq2" class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="connectionFactory" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg><Ref id="amq2"/></Arg>
        <Arg>jms/connectionFactory</Arg>
        <Arg>
            <New class="org.apache.activemq.ActiveMQConnectionFactory">
                <Arg>failover:(tcp://localhost:63616,tcp://localhost:64616)</Arg>
            </New>
        </Arg>
    </New>
    <New id="url" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg><Ref id="amq2"/></Arg>
        <Arg>jmx/url</Arg>
        <Arg>
            <New class="java.lang.String">
                <Arg>service:jmx:rmi:///jndi/rmi://localhost:1399/jmxrmi,service:jmx:rmi:///jndi/rmi://localhost:1499/jmxrmi</Arg>
            </New>
        </Arg>
    </New>
</Configure>
Step 7.
Now we can start jetty using the following command:
java -Dwebconsole.type=jndi -jar start.jar
This command informs the brokers' web consoles to use the JNDI properties to provision the ConnectionFactory and the JMX connection.

Step 8.
In addition to the master/slave configuration required for the ActiveMQ brokers, which I will cover in my next post, we also need to disable the Jetty configuration.  The default configuration file for ActiveMQ is activemq.xml located in the /conf directory of the broker.  At the bottom of this file you will find an import tag that is used to import the resource: jetty.xml.  This should be commented out as follows:
<!--<import resource="jetty.xml"/>-->
Step 9.
Now we are ready to start our master/slave configuration of brokers.  For each broker run the following command:
./bin/activemq console
The Result of This Configuration
Now lets take a look at how the web console and Jetty behave with this configuration.  In your browser navigate to http://localhost:8080/amq1.  You should see that this connects you to broker amq1M which is the master in the amq1 pair.

ActiveMQ - amq1M (Master)

Now if we go to the terminal where the broker amq1M was started and issue a 'control c' command to kill it, when the browser is refreshed the connection will failover to broker amq1S which is the slave in the amq1 pair.

ActiveMQ - amq1S (Slave)

To check on the amq2 broker pairs, navigate to http://localhost:8080/amq2.  You should see this connects you to amq2M which is the master in the amq2 pair of brokers.

ActiveMQ - amq2M (Master)
Again, if we go to the terminal where the broker amq2M was started and issue a 'control c' command to kill it, when the browser is refreshed the connection will failover to broker amq2S which is the slave in the amq2 pair.
ActiveMQ - amq2S (Slave)
Summary
Using this configuration to set up multiple instances of ActiveMQ broker pairs in a single Jetty instance you can see how it could simplify managing and accessing the web consoles for all brokers as the environment scales to support many instances of ActiveMQ master/slave pairs.  This eliminates the need for each individual broker to have separate URLs and ports to access the web console.  In a followup to this post I will show how the brokers were configured to support a master/slave configuration.

Web Service Console (video game CLI)

Published at DZone with permission of Jason Sherman. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Get Cell Data From an Excel Spreadsheet Using APIs in Java
  • 8 Strategies To Accelerate Web Portal Development
  • A Better Web3 Experience: Account Abstraction From Flow (Part 1)
  • Managed MQTT Broker Comparison — Console/Dashboard Features

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook