Integrate Apache ActiveMQ
In this procedure, you will learn how to integrate Kaazing Gateway and Apache ActiveMQ, a powerful open source messaging server.
Apache ActiveMQ provides a factory class in their JAR files. The Apache ActiveMQ factory class that ships in the Kaazing Gateway bundle is org.apache.activemq.jndi.ActiveMQInitialContextFactory
in the JAR file activemq-client-5.14.0.jar
. To use the jms
service with a different version or instance of Apache ActiveMQ, you copy the JAR files to GATEWAY_HOME/lib/ext
and specify the name of the factory class in the jms
service configuration element.
The following table lists the Java Archive (JAR) files needed by the Gateway for different versions of Apache ActiveMQ.
Apache ActiveMQ version | JAR files to copy into GATEWAY_HOME/lib/ext |
---|---|
5.8.0 | activemq-broker-5.8.0.jar, activemq-client-5.8.0.jar, hawtbuf-1.9.jar |
5.9.1 | activemq-broker-5.9.1.jar, activemq-client-5.9.1.jar, hawtbuf-1.9.jar |
5.10.0 | activemq-broker-5.10.0.jar, activemq-client-5.10.0.jar, hawtbuf-1.10.jar |
5.14.0 | activemq-broker-5.14.0.jar, activemq-client-5.14.0.jar, hawtbuf-1.14.jar (shipped with the Gateway) |
To Integrate Apache ActiveMQ
- Download and install Apache ActiveMQ following the instructions in the Apache ActiveMQ documentation.
- Download and install the Gateway as described in Setting Up the Gateway.
- To use a version of Apache ActiveMQ other than 5.14.0, remove the existing Apache ActiveMQ 5.14.0 files from the
GATEWAY_HOME/lib/ext
folder:activemq-broker-5.14.0.jar
,activemq-client-5.14.0.jar
,hawtbuf-1.14.jar
. - Copy the appropriate JAR files from
ACTIVEMQ_HOME/lib
toGATEWAY_HOME/lib/ext
. See the above table for the exact JAR names for your version of ActiveMQ.activemq-broker-5.x.y.jar
activemq-client-5.x.y.jar
- Open the file
GATEWAY_HOME/conf/gateway-config.xml
in a text editor and locate thejms
service element (search for “JMS Service”). -
Update the
properties
element of the jms service to connect to the hostname for ActiveMQ (in this example, we useactivemq.example.com
to connect to ActiveMQ on a remote machine):<service> <name>JMS Service</name> <description>JMS Service</description> <accept>ws://${gateway.hostname}:${gateway.extras.port}/jms</accept> <type>jms</type> <properties> <connection.factory.name>ConnectionFactory</connection.factory.name> <context.lookup.topic.format>dynamicTopics/%s</context.lookup.topic.format> <context.lookup.queue.format>dynamicQueues/%s</context.lookup.queue.format> <env.java.naming.factory.initial> org.apache.activemq.jndi.ActiveMQInitialContextFactory </env.java.naming.factory.initial> <env.java.naming.provider.url> tcp://activemq.example.com:61616 </env.java.naming.provider.url> </properties> <realm-name>demo</realm-name> <!-- <authorization-constraint> <require-role>AUTHORIZED</require-role> </authorization-constraint> --> <cross-site-constraint> <allow-origin>http://${gateway.hostname}:${gateway.extras.port}</allow-origin> </cross-site-constraint> </service>
Notes
- To learn how to secure your JMS configuration, see Secure Your JMS Configuration.
-
The
context.lookup
properties in the above example make use of an ActiveMQ feature that allows special JNDI namespaces to be reserved for dynamic topics and queues (dynamic means they are not predefined in the broker but are instead created by the application as needed). If you wish to use dynamic destinations but your broker does not have this JNDI feature, then you can set thedestination.strategy property
of yourjms
service tosession
to tell the Gateway to use the JMS Session methodscreateTopic()
orcreateQueue()
to create topics and queues as needed.Client applications (using the Kaazing Gateway JMS client library) can then lookup/create their
Topic
andQueue
objects using either thesession.createTopic()
method (for example,Topic myTopic = session.createTopic("myTopic");
) or by performing a JNDI lookup using theinitialContext.lookup()
method (for example,Topic myTopic = initialContext.lookup("/queue/myQueue");
). TheinitialContext.lookup()
method is available to use after creating the JNDIInitialContext
object when creating the JMS connection. - The provider URL
tcp://${gateway.hostname}:61616
is used because this is a production deployment example. If the broker is run on the same computer as the Gateway, then the${gateway.hostname}
service-default could be used.
JMS Integration Verification
To verify that the JMS integration is working, perform the following steps:
- Start your instance of Apache ActiveMQ.
- Start the Gateway as described in Setting Up the Gateway.
- Download or clone the Kaazing JavaScript JMS demo from https://github.com/kaazing/javascript.client.tutorials. Follow the steps in the repo's README.md file for building and running the demo locally.
- In Location, enter
ws://localhost:8001/jms
. - Click Connect and test the JMS features.
Subscription and Destination Support
Kaazing Gateway integration with Apache ActiveMQ has the following subscription and destination support:
- Durable subscriptions are not supported.
- Dynamic destinations are supported.
- Static destinations are supported.
See Also
- For information on troubleshooting JMS integration, see Troubleshoot JMS Integration.
- For information on troubleshooting JMS clients, see Troubleshoot Your Clients.
- For general troubleshooting information, see Troubleshoot Kaazing Gateway.