Saturday, June 29, 2013

ActiveMQ as a Windows Service using YAJSW


Objective:

This blog is to demonstrate how to run ActiveMQ JMS Broker as a Windows Service using YAJSW.

Introduction:

ActiveMQ JMS Broker(s) is a vital part of messaging infrastructure in an enterprise. In order to ensure that the ActiveMQ process stays up and running, it is best to run it as a service using a service wrapper such as Tanuki or YAJSW. Running ActiveMQ as a service helps in automatically restarting ActiveMQ process when the host machine restarts (planned or unplanned).
Service Wrapper ensures that the ActiveMQ process remains healthy. It can be configured to restart ActiveMQ process if it was to determine that the process is hung or not responding to ping. However, I must say that this is not a substitute for fixing issue(s) which actually cause ActiveMQ to hang or shut down. Service Wrapper may cure the symptom with a restart but it will not fix the root cause. It is best to troubleshoot to determine what is troubling the ActiveMQ process in order to prevent production nightmares :) Some of the common issues that I have seen relate to memory & connection leaks and inadequate capacity configuration.

Tanuki Wrapper is one the most popular open source Service Wrappers but it does not offer community edition for 64bit Windows OS as of this writing :)

Please read the Tanuki Service Wrapper release notes here:
http://wrapper.tanukisoftware.com/doc/english/download.jsp

There is a viable open source alternative in YAJSW. If you are interested in running ActiveMQ as a Windows Service on a 64bit Windows OS, you may want to consider YAJSW. There may be other alternatives but I have found YAJSW sufficient. 

Overview:

In this article, I will show how to use YAJSW to run ActiveMQ as a Windows Service. We will use ActiveMQ version 5.7.0, YAJSW version 11.03 on 64bit Windows 7 OS. Usually when you register a process to run as a service, there are additional parameters to think about such as security - which user or user groups can administer this service,  determine which interested parties receive process health status notifications, etc. In this example, we will consider a plain vanilla use case with out-of-the-box settings of ActiveMQ and YAJSW.

The actual process can be summarized in 3 easy steps. 
  1. Run YAJSW "getConfig.bat" script against a live ActiveMQ process to generate YAJSW configuration file
  2. Edit the configuration file to change a few settings
  3. Run YAJSW "installService.bat" script to register ActiveMQ process to run as a Windows Service. 
Prerequisites:
  1. Install ActiveMQ 5.7.0
  2. Install YAJSW 11.03
  3. Windows 7
  4. JDK 1.6+
Deep Dive:

Launch ActiveMQ using the default activemq.bat script


Find the process ID using jps -v


The ActiveMQ process ID is 3024

Let's generate YAJSW configuration now. We will use genConfig.bat script and pass the ActiveMQ process ID as an argument.


The generated configuration is a good start but is not good enough. We still need to edit wrapper.conf file in c:\yajsw-stable-11.03\conf directory and provide the settings listed below:

wrapper.working.dir=C:\\apache-activemq-5.7.0\\bin\\

ActiveMQ uses a runnable jar "run.jar" so we need to specify that accordingly

# Java Application main class
#wrapper.java.app.mainclass=

# or jar file
wrapper.java.app.jar=C:\\apache-activemq-5.7.0\\bin\\run.jar

# Name of the service
wrapper.ntservice.name=ActiveMQ

# Display name of the service
wrapper.ntservice.displayname=ActiveMQ-Service
# Description of the service
wrapper.ntservice.description=ActiveMQ Broker Service

# Log file to use for wrapper output logging.
wrapper.logfile=C:\\yajsw-stable-11.03\\log\\wrapper.log

Now let's install ActiveMQ as a Windows Service


Let's confirm if service got registered correctly

start -> run -> services.msc



Details:

In order to uninstall, run the uninstallService.bat


Conclusion:

We have just seen how to install ActiveMQ as a Windows Service using YAJSW on 64bit Windows. 

No comments:

Post a Comment