Sunday, February 9, 2014

Install and Configure ActiveMQ 5.9.0

Introduction

ActiveMQ 5.9 was release on October 23, 2013, per this web page. Many new features have been introduced since, such as LevelDB, hawtio, etc. I am going to explain these features in detail in the this and following blogs. In this blog, I am going to demonstrate how to install and configure activemq instance on MacOS [the same is for linux].

Installation

First, download the binary distribution from activemq 5.9.0 release. Then, execute the following commands to install the default configuration:

cd ~/Downloads
tar -vxzf tar -vxzf apache-activemq-5.9.0-bin.tar.gz
mv apache-activemq-5.9.0 ~/.
cd ~/apache-activemq-5.9.0

The above commands created activemq default at apache-activemq-5.9.0. Now we are ready to start activemq by execute the following commands

cd bin
./activemq start

The start command starts the activemq process as a background running process. We can check the java process by the following command

ps -eaf | egrep java | egrep -v egrep

You should see the following output:

[/Users/Gary2013/apache-activemq-5.9.0/bin]$ ps -eaf | egrep java | egrep -v egrep 
  501  9148     1   0  4:17PM ttys001    0:15.53 /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/java -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Dhawtio.realm=activemq -Dhawtio.role=admins -Dhawtio.rolePrincipalClasses=org.apache.activemq.jaas.GroupPrincipal -Djava.security.auth.login.config=/Users/Gary2013/apache-activemq-5.9.0/conf/login.config -Dcom.sun.management.jmxremote.port=11099 -Dcom.sun.management.jmxremote.password.file=/Users/Gary2013/apache-activemq-5.9.0/conf/jmx.password -Dcom.sun.management.jmxremote.access.file=/Users/Gary2013/apache-activemq-5.9.0/conf/jmx.access -Dcom.sun.management.jmxremote.ssl=false -Djava.awt.headless=true -Djava.io.tmpdir=/Users/Gary2013/apache-activemq-5.9.0/tmp -Dactivemq.classpath=/Users/Gary2013/apache-activemq-5.9.0/conf; -Dactivemq.home=/Users/Gary2013/apache-activemq-5.9.0 -Dactivemq.base=/Users/Gary2013/apache-activemq-5.9.0 -Dactivemq.conf=/Users/Gary2013/apache-activemq-5.9.0/conf -Dactivemq.data=/Users/Gary2013/apache-activemq-5.9.0/data -jar /Users/Gary2013/apache-activemq-5.9.0/bin/activemq.jar start
[/Users/Gary2013/apache-activemq-5.9.0/bin]$ 

The above output from checking the java process is very important to understand what arguement have been passed to the activemq java process, such as, JDK version, default installation, etc. At this point, we can use activemq for messaging. I am going to explain this in later session together with apache camel application development. ActiveMQ comes with a web console which is very important from admin point of view. To login to console, we can using the following url:

http://localhost:8161/

Click the the link of Manage ActiveMQ broker. From this link, we will see virtually all the information about the ActiveMQ instance. If you are familiar with the old version, you can choose the link to point to the old version console. Somehow, I like the old console better. Of course, the new console provides much more information such as jmx. However, for that part, I prefer to use jvisualvm to get more information about the activemq process. In order to use jvisualvm to do so, we need to enable jmx configuration for activemq.

Enable JMX

JMX Configuration Setup

To enable JMX, we need to modify the following two files:

$ACTIVEMQ_HOME/bin/activemq
$ACTIVEMQ_HOME/conf/activemq.xml

activemq is a script which has option of start, restart, stop.
activemq.xml is the configuration file for the ActiveMQ broker.

Modify activemq

Change the activemq file for the following lines:

184  ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11099 "
185  ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password"
186  ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access"
187  ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false"
188 #ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote"

Make the the jmx.password file has the permission of 600. By default, jmx.password has the line as the following:

     admin activemq

Modify the file activemq.xml

40     

The new line has added useJmx="true"

Now we need to restart activemq by executing the following command:

$ACTIVEMQ_HOME/bin/activemq restart

OK, we have configured activemq with jmx enabled. What port is JMX running? From the configuration file, we know it should be running on 11099 based on the line of:

ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11099 "

Verifying the JMX

To verify if the JMX is working or not, we can use JVisualVM which is coming with JDK. On the command line terminal, you can type "jvisualvm", the GUI will come up. Here is the configuration I have:

When you configure the JMX, you will need to add the following properties:<

   connection url: http:localost:11099
   user name: admin
   password:  activemq

Important Ports Used By ActiveMQ

Let check what important ports activemq is running. Execute the following command:

netstat -an | egrep LISTEN

On my local MacBook Pro, I see the following ports are open:

[/Users/Gary2013/apache-activemq-5.9.0/conf]$ netstat -an | egrep LISTEN
tcp46      0      0  *.8161                 *.*                    LISTEN     
tcp46      0      0  *.61614                *.*                    LISTEN     
tcp46      0      0  *.1883                 *.*                    LISTEN     
tcp46      0      0  *.61613                *.*                    LISTEN     
tcp46      0      0  *.5672                 *.*                    LISTEN     
tcp46      0      0  *.61616                *.*                    LISTEN     
tcp46      0      0  *.51776                *.*                    LISTEN     
tcp46      0      0  *.11099                *.*                    LISTEN     
tcp46      0      0  *.51775                *.*                    LISTEN     
tcp4       0      0  127.0.0.1.37483        *.*                    LISTEN     
tcp4       0      0  *.49204                *.*                    LISTEN     
tcp6       0      0  fdfd:b5d6:df5f:c.4488  *.*                    LISTEN     
tcp46      0      0  *.3306                 *.*                    LISTEN     
tcp4       0      0  127.0.0.1.631          *.*                    LISTEN     
tcp6       0      0  ::1.631                *.*                    LISTEN     
[/Users/Gary2013/apache-activemq-5.9.0/conf]$ 

We can see 11099 port is open. That is JMX port. The other important ports are: 61613, 61613, 61616 and 8161. So, where are these ports are defined. An experience developer, use egrep command to file this out. Of course, you can look up the documentation, but that is a slow process. And many times it is not very reliable, because the most documentation are not up-to-date.

egrep -r "8161|61613|61616" . | egrep xml

We now know that 8161 is defined in the file jetty.xml and other ports are defined at activemq.xml. There are other 2 ways to check what ports are running. One is through the url: http://localhost:8161/hawtio/#/logs. The other is view the load at $ACTIVEMQ_HOME/data/activemq.log

2014-02-09 16:17:20 INFOorg.apache.activemq.store.kahadb.plist.PListStoreImpl PListStore:[/Users/Gary2013/apache-activemq-5.9.0/data/localhost/tmp_storage] started
2014-02-09 16:17:20 INFOorg.apache.activemq.broker.BrokerService Using Persistence Adapter: KahaDBPersistenceAdapter[/Users/Gary2013/apache-activemq-5.9.0/data/kahadb]
2014-02-09 16:17:21 INFOorg.apache.activemq.store.kahadb.MessageDatabase KahaDB is version 5
2014-02-09 16:17:21 INFOorg.apache.activemq.store.kahadb.MessageDatabase Recovering from the journal ...
2014-02-09 16:17:21 INFOorg.apache.activemq.store.kahadb.MessageDatabase Recovery replayed 15831 operations from the journal in 0.33 seconds.
2014-02-09 16:17:21 INFOorg.apache.activemq.broker.BrokerService Apache ActiveMQ 5.9.0 (localhost, ID:guojiangs-mbp.home-51782-1391984241450-0:1) is starting
2014-02-09 16:17:21 INFOorg.apache.activemq.transport.TransportServerThreadSupport Listening for connections at: tcp://guojiangs-mbp.home:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600
2014-02-09 16:17:21 INFOorg.apache.activemq.broker.TransportConnector Connector openwire started
2014-02-09 16:17:21 INFOorg.apache.activemq.transport.TransportServerThreadSupport Listening for connections at: amqp://guojiangs-mbp.home:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600
2014-02-09 16:17:21 INFOorg.apache.activemq.broker.TransportConnector Connector amqp started
2014-02-09 16:17:21 INFOorg.apache.activemq.transport.TransportServerThreadSupport Listening for connections at: stomp://guojiangs-mbp.home:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600
2014-02-09 16:17:21 INFOorg.apache.activemq.broker.TransportConnector Connector stomp started
2014-02-09 16:17:21 INFOorg.apache.activemq.transport.TransportServerThreadSupport Listening for connections at: mqtt://guojiangs-mbp.home:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600
2014-02-09 16:17:21 INFOorg.apache.activemq.broker.TransportConnector Connector mqtt started
2014-02-09 16:17:21 INFOorg.apache.activemq.transport.ws.WSTransportServer Listening for connections at ws://guojiangs-mbp.home:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600
2014-02-09 16:17:21 INFOorg.apache.activemq.broker.TransportConnector Connector ws started
2014-02-09 16:17:21 INFOorg.apache.activemq.broker.BrokerService Apache ActiveMQ 5.9.0 (localhost, ID:guojiangs-mbp.home-51782-1391984241450-0:1) started
2014-02-09 16:17:21 INFOorg.apache.activemq.broker.BrokerService For help or more information please see: http://activemq.apache.org
2014-02-09 16:17:22 INFOio.hawt.jmx.JmxTreeWatcher Welcome to hawtio 1.2-M23 : http://hawt.io/ : Don't cha wish your console was hawt like me? ;-)
2014-02-09 16:17:22 INFOio.hawt.web.AuthenticationFilter Starting hawtio authentication filter, JAAS realm: "activemq" authorized role: "admins" role principal classes: "org.apache.activemq.jaas.GroupPrincipal"
2014-02-09 16:17:22 INFOio.hawt.web.UploadServlet Using file upload directory: /Users/Gary2013/apache-activemq-5.9.0/tmp/uploads
2014-02-09 16:17:22 INFO/hawtio jolokia-agent: Using access restrictor classpath:/jolokia-access.xml
2014-02-09 16:17:22 INFOorg.apache.activemq.web.WebConsoleStarter ActiveMQ WebConsole available at http://localhost:8161/

4 comments:

  1. How can we configure SSL on Activemq. Please suggested me any one. Thanks in advance.

    ReplyDelete
  2. Nice to read your article! I am looking forward to sharing your adventures and experiences. Plumber Glendale CA

    ReplyDelete

  3. It is amazing to visit your site. Thanks for sharing this information, this is useful to me...
    Mulesoft Self Learning
    Mulesoft Online Training in India

    ReplyDelete

Anypoint Studio Error: The project is missing Munit lIbrary to run tests

Anypoint Studio 7.9 has a bug. Even if we following the article: https://help.mulesoft.com/s/article/The-project-is-missing-MUnit-libraries-...