Overview

Chapter 8. Integrating ActiveMQ with application servers

In this chapter, ActiveMQ is presented as a message broker that can be integrated into application-server environments instead of running only as a standalone JVM process. The discussion contrasts two broad server styles: web containers such as Tomcat and Jetty, and Java EE containers such as Geronimo and JBoss. The overall goal is to show how an application server’s own facilities, especially JNDI and resource adapters, can be used to expose ActiveMQ resources to deployed applications and manage broker startup in a way that fits the container.

A small sample web application is used throughout to prove each integration path. The app is intentionally simple: it looks up a connection factory and a queue from JNDI, uses Spring to inject them into a message-sending service, and then sends a JMS message that is consumed by a listener container and delegated to a message handler. The same core application is reused in multiple variants so it can match the deployment style of each server, whether that means local or global JNDI in Tomcat and Jetty, or more specialized deployment descriptors and classloader adjustments in Geronimo and JBoss.

The chapter then walks through concrete integration approaches for each server family. For Tomcat and Jetty, ActiveMQ can be started through a connection factory configured with a broker URI, while JNDI resources are declared either locally for a single web app or globally for all apps in the container. For Geronimo and JBoss, the broker is typically started through the ActiveMQ JCA resource adapter, and the sample application is adjusted to use the server’s deployment descriptors, transaction support, and classloading rules. The chapter closes by explaining ActiveMQ’s client-side JNDI support, noting that it is local in-memory JNDI rather than a remote provider, and emphasizing that server-supplied JNDI remains the common best practice for shared JMS administration objects.

The project structure for the sample web application that demonstrates local JNDI configuration
The flow of a message through the classes in the sample web application
A screenshot of the only page in the web application demonstrates that it’s intentionally simplistic.
Upon sending a JMS message using the web application, a message appears in the web application and then fades away to let you know that the message was sent successfully.
The Geronimo console simplifies the configuration and management of Geronimo.
The Geronimo console provides the ability to manage ActiveMQ (the JMS Server) and the ActiveMQ resources (JMS Resources).
The Geronimo console simplifies the management of the ActiveMQ configuration.
The Geronimo console also simplifies the management of JMS resources.
Accept the default values when configuring the ActiveMQ resource adapter’s server connection.
Use the Geronimo console to create a JMS connection factory and a JMS destination for ActiveMQ.
Easily create a JMS connection factory for ActiveMQ via the Geronimo console.
Use the Geronimo console to configure the connection factory.
The connection factory has been created successfully.
Create a JMS destination that’s of type javax.jms.Queue.
Customize the destination using the Geronimo console.
Now the connection factory and the destination have been created and are ready to be deployed.
Now the FooGroup JMS resource group has been created and deployed.
Note that the information provided in the <moduleId> element is used to identify the web application when it’s deployed to Geronimo.

FAQ

What is the main goal of Chapter 8 in ActiveMQ in Action?The chapter focuses on integrating ActiveMQ with application servers, rather than running it as a standalone broker or embedding it only inside a Java application. It shows how to use application server features such as JNDI and JCA to start the broker and expose JMS resources.
Which application servers are covered in this chapter?The chapter covers Apache Tomcat, Jetty, Apache Geronimo, and JBoss. Tomcat and Jetty are treated as web containers, while Geronimo and JBoss are covered as Java EE containers.
What are the two major tasks involved when deploying ActiveMQ to an application server?The two major tasks are starting the broker and providing access to JMS destinations such as connection factories and queues. Different application servers use different approaches to accomplish these tasks.
How does the chapter use JNDI with Tomcat and Jetty?For Tomcat and Jetty, the chapter uses JNDI to register the JMS connection factory and queue so that the web application can look them up. It demonstrates both local JNDI, which is limited to one application, and global JNDI, which is available to all applications in the container.
What is the difference between local JNDI and global JNDI?Local JNDI makes resources available only to a specific web application, while global JNDI exposes those resources to all applications deployed in the container. The chapter shows both styles in Tomcat and Jetty.
How does ActiveMQ start a broker through a connection factory?ActiveMQ can create a broker when a connection factory is configured with a broker URI for a broker that does not yet exist. When the connection factory tries to connect, ActiveMQ starts the broker automatically if needed.
Why does the sample web application use Spring in this chapter?Spring is used to perform JNDI lookups and inject the connection factory and queue into the message-sending service. It also provides the JMS template and listener container used to send and consume messages.
What is different about integrating ActiveMQ with Geronimo compared to Tomcat and Jetty?Geronimo uses JCA resource adapters instead of starting the broker through a simple JNDI connection factory. The chapter also requires Geronimo-specific deployment descriptors and configuration such as geronimo-web.xml and a custom JMS resources group.
What is different about integrating ActiveMQ with JBoss?JBoss uses an ActiveMQ JCA resource adapter deployed in the server’s deploy directory, along with a JBoss-specific datasource-style descriptor named activemq-ds.xml. The sample application also needs JBoss-specific adjustments, including transaction support and VFS-related Spring configuration.
What does the chapter say about client-side JNDI support in ActiveMQ?ActiveMQ provides a local, client-side JNDI context through an InitialContextFactory and a jndi.properties file. However, it does not provide a remotely accessible JNDI provider, so remote lookup is typically handled by an application server’s JNDI service instead.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • ActiveMQ in Action ActiveMQ in Action ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • ActiveMQ in Action ActiveMQ in Action ebook for free