Using BlazeDS with Jetty and a stand-alone ActiveMQ server
In order to use JMS messaging together with BlazeDS you have to connect BlazeDS to a message broker like ActiveMQ, OpenMQ, or JBoss Messaging.
The turnkey server which comes with BlazeDS is a Tomcat that uses an embedded ActiveMQ broker.
But what about using BlazeDS in a webapp that runs in Jetty and connects to a stand-alone ActiveMQ server?
This is especially interesting when building a BlazeDS/Flex app with Maven. How do I get the Maven Jetty plugin to talk to ActiveMQ?
This post lists the necessary steps.
ActiveMQ
- Download the ActiveMQ server from activemq.apache.org
- Unzip the archive
- Go to the bin directory
- Start the AcitveMQ server by running
activemq
Jetty
The JMS components a webapp is using when running in Jetty can be declared in a file called jetty-env.xml.
The connection factories and JMS destinations are then available through JNDI.
- Add a jetty-env.xml to the WEB-INF directory of your web application archive (WAR). This file is automatically found by Jetty.
- Configure connection factories, queues, and topics in the jetty-env.xml. See the Jetty reference on syntax details.
jms/topicConnectionFactory tcp://localhost:61616 jms/todoTopic TodoTopic
BlazeDS
- Add the BlazeDS configuration files to the directoy WEB-INF/flex of your WAR.
- Configure the destinations in the messaging-config.xml. Use the JNDI names specified in the jetty-env.xml
Topic javax.jms.TextMessage java:comp/env/jms/topicConnectionFactory java:comp/env/jms/todoTopic NON_PERSISTENT DEFAULT_PRIORITY AUTO_ACKNOWLEDGE
Maven
- Add ActiveMQ to the dependencies in the pom.xml of your webapp.
org.apache.activemq activemq-core 5.1.0
Let’s go
You are now ready to start your web application with
mvn jetty:run-war
By default ActiveMQ automatically creates the destinations required by a client. You can check the ActiveMQ admin pages if your destinations have been successfully created. The admin pages can be found under http://localhost:8161/admin.