Stomp Client talking to ActiveMQ

From MidrangeWiki
Jump to: navigation, search

This article won't cover what Stomp, Message Queuing or ActiveMQ is but shows how those two software packages (RPG Stomp Client and ActiveMQ) can work together.

Stomp client installation

  • install all required service programs and includes (see stomp website on rpgnextgen.com)
  • download stomp client from rpgnextgen.com
  • upload archive file to IBM i server
  • enter QShell (QSH)
  • unpack archive file (tar -xf stomp-x.x.x.tar)
  • adjust Makefile (place for binaries BIN_LIB, place for copybooks INCLUDES)
  • execute make targets all and clean => "make all clean"

The result should be a service program STOMP in your configured library or QGPL if you left the configuration as it was.

Note: It is a good practice to have one directory in the IFS for software packages like /usr/local/src and one directory for copybooks like /usr/local/include. Both can also be links to the QOpenSys filesystem (f. e. ln -s /QOpenSys/usr/local/src /usr/local/src).

Note: For executing the Makefile it needs to have a non-EBCDIC CCSID. This can be checked with ls -S. Easiest way for doing this is using the convert.sh script from rpgnextgen.com.

Note: RPG Next Gen Editor can be used to edit the stream files on the system (like Makefile or activemq.xml).


ActiveMQ

Installation

ActiveMQ is an Apache project and can be downloaded from apache.org. The current version 5.5.0 needs Java 1.6 as a minimal requirement. If the IBM i server does not have the Java Runtime Environment 1.6 installed then use the ActiveMQ version 5.4.2 which has Java 1.5 as a minimal requirement.

Note: To check the current Java version execute the command "JAVA *VERSION". The system can be installed with several JRE versions side by side. The JRE version for the whole system can be set in the file /QIBM/UserData/Java400/SystemDefault.properties. On a user level it can be set in the file /home/user/SystemDefault.properties. The file is a standard properties file with key/value pairs. The entry for the version would be: java.version=1.5

Download the zip-package as this can be easily extracted on the IBM i server with the jar utility (which should be available on each system), jar -xf apache-activemq-5.4.2-bin.zip.

Note: It is also a good practice to have one directory for applications like ActiveMQ. A good place would be /var/lib which would result in /var/lib/apache-activemq-5.4.2. To have an easier access to the directory a link can be created: ln -s apache-activemq-5.4.2 activemq


Configuration

ActiveMQ supports various protocols and for many of those protocols is an example configuration in the conf subdirectotry of the application directory (like /var/lib/activemq/conf). An example configuration file for Stomp can also be found.


Starting

The bin subdirectory contains the start script for the application, activemq. The application can be started from QShell by going to the bin subdirectory of the application and execute

./activemq start &

This will start ActiveMQ with the default configuration conf/activemq.xml in a separate process/job (take note of the ampersand).

To use another configuration just add it to the start command

./activemq start xbean:../conf/activemq-stomp.xml &

Note: If the execution of the activemq script results in an error message "Permission denied" than the execute permission bit on the file is not set. It can be checked with ls -l. To add the execute permission run the QShell command chmod o+x activemq.

If the application runs successful can be verified by various means.

  • WRKUSRJOB — there should be one BATCHI job with the name QP0ZSPWP with the current function JVM-xxx which means there is a Java Virtual Machine running
  • log file — the log file should contain messages for the start of the application
  • ports — the ports for the stomp connectors should now be in use by the application (by default 61612 and 61613), command NETSTAT OPTION(*CNN)


Logging

By default the logs for ActiveMQ are placed in the data subdirectory and are rolled every 1024kb. The logging can be configured in the conf/log4j.properties file.


Monitor Message Queuing System

Server Setup

The log files are a good start to see what is happening (depending on the configured log levels). But sometimes you need to have a look inside the application. Java has a very nice technology for this: JMX - Java Management Extension.

ActiveMQ supports JMX. By default it is not enabled. It can be enable in the configuration file.

<broker useJmx="true">
   ...
 
       <managementContext>
           <managementContext createConnector="true" connectorPort="61699" />
       </managementContext>

   ...

</broker>

The command NETSTAT OPTION(*CNN) now shows also the port 61699 listening for connections.

The default user/password for connecting to the application is admin/activemq (see .

For a detailed description on how to configure ActiveMQ for monitoring have a look at the documentation on the web site http://activemq.apache.org/jmx.html.