ActiveMQ and Apache Tomcat: Perfect Partners

posted by bsnyder on December 13, 2010 07:04 AM

This article is excerpted from the forthcoming book ActiveMQ In Action ( by Bruce Snyder, Rob Davies and Dejan Bosanac (Manning Publications, ISBN: 1933988940)

At one time or another, every software developer has the need to communicate between applications or transfer data from one system to another. Not only are there many solutions to this sort of problem, but depending on your constraints and requirements, deciding how to go about such a task can be a big decision. Business requirements oftentimes place restrictions on items that directly impact such a decision including performance, scalability, reliability and more. There are many applications that we use every day that impose just such requirements including ATMs, airline reservation systems, credit card systems, point-of-sale systems and telecommunications just to name a few. Where would we be without most of these applications in our daily lives today?

When it comes to developing and deploying Java applications, it is extremely common to use Tomcat as a runtime container. As you expand your Java applications, new business needs arise including the ability to communicate with other applications, the need to scale an application architecture and quite possibly the need to decrease application coupling just to name a few. These requirements and many more can be addressed through the use of ActiveMQ with Tomcat.

In a series of articles, you will learn about the integration of ActiveMQ and Tomcat. In the first article, you will learn a bit about Java Servlet technology, Tomcat and you will be introduced to Apache ActiveMQ. Future articles will continue to dive deeper into the topic of integrating ActiveMQ with Tomcat.

Using Tomcat

Apache Tomcat is arguably the most widely used Java web container available today. Tomcat is used for both development and production throughout the world because it is extremely robust, highly configurable and commercially supported by a number of companies. Tomcat also provides facilities for integrating third party resources such as JDBC data sources, JMS connection factories, etc. and making them JNDI accessible. This is how ActiveMQ will be integrated with Tomcat. Before proceeding, you need to download Apache Tomcat 6.0.26 ( and expand it on your computer.

Simplying Web Applications With Tomcat

Prior to the invention of Java Servlets, developing web applications meant doing CGI (Common Gateway Interface) programming. Although CGI is a powerful tool, it also comes with some drawbacks. Although some technologies came about to address some of the issues, Java Servlets turned out to be a much more powerful alternative. Servlets provide better performance, portability, standardized exception handling, the ability to manage sessions, a standardized security model and much more. Servlets abstract away low-level functions such as protocols, sockets, threading, etc. allowing you to focus on application development. In addition to these myriad benefits, servlets also provide standardization in both the API and the packaging. Because of this, as long as a given servlet abides by the specification, it should run just fine in any servlet container.

Tomcat offers a great deal of functionality in a very small package. Not only is Tomcat a highly capability and very lightweight runtime container for Java Servlet based application, but it is also quite easy to bootstrap a so-called headless application in Tomcat (a Java application without a GUI). Tomcat provides the ability to scale the container independent of the deployed applications and Tomcat is fully instrumented via JMX for management and monitoring capabilities. With all of these incredible features, it's not surprising to learn how truly widespread Tomcat really is in the business world. It is used in development and production by many Fortune 500 businesses as well as by a great of small and medium sized businesses.

Clearly Tomcat is an incredibly capable and a highly popular application server. So how does ActiveMQ fit into this picture?

Using ActiveMQ: Why and When?

Apache ActiveMQ is arguably the most popular open source message-oriented middleware in existence today. ActiveMQ was intended to be used as the JMS spec intended, for remote communications between distributed applications. To better understand what this means, the best thing to do is take a look at a few of the ideas behind distributed application design, specifically, communications.

Loose Coupling and ActiveMQ

ActiveMQ provides the benefits of loose coupling for application architecture. Loose coupling is commonly introduced into an architecture to mitigate the classic tight coupling of Remote Procedure Calls (RPC). Such a loosely coupled design is considered to be asynchronous where the calls from either application have no bearing on one another; there is no interdependence or timing requirements. The applications can rely upon ActiveMQ's ability to guarantee message delivery. Because of this, it is often said that applications sending messages just fire-and-forget. That is, they send the message to ActiveMQ and are not concerned with how or when the message is delivered. Furthermore, the consuming applications have no concerns with where the messages originated or how they were sent to ActiveMQ. This is an especially powerful benefit in heterogeneous environments allowing clients to be written using different languages and even possibly different wire protocols. ActiveMQ acts as the middleman allowing heterogeneous integration and interaction in an asynchronous manner.

When considering distributed application design, application coupling is important. Coupling refers to the interdependence of two or more applications or systems. An easy way to think about coupling is to consider the affect of changes to any application in the system; the implications across the other applications in the architecture as features are added. Do changes to one application force changes to other applications involved? If the answer is yes, then those applications are tightly coupled. However, if one application can be changed without affecting other applications, then those applications are more loosely coupled. The overall lesson here is that tightly coupled applications are more difficult to maintain compared to loosely coupled applications. Said another way, loosely coupled applications can more easily deal with unforeseen changes.

Technologies such as COM, CORBA, DCE and EJB that make use of RPC techniques are said to be tightly coupled. Using RPC, when one application calls another application, the caller is blocked until the callee returns control to the caller. The diagram in Figure 1 below depicts this concept.

Figure 1. Two tightly-coupled applications using remote procedure calls to communicate

Two tightly-coupled applications using remote procedure calls to communicate

The caller (application one) in Figure 1 is blocked until the callee (application two) returns control. Many system architectures use RPC and are very successful. However, there are many disadvantages to such a tightly coupled design, most notable is the higher amount of maintenance that is required since even small changes ripple throughout the system architecture. Also, correct timing is a necessity between the two applications that are tightly coupled. Both applications must be available at the same time for the request from application one to reach application two (label #1), and for the response to travel from application two to application one (label #2). Such timing requirements can be very cumbersome. Compare such a tightly coupled design with a design where two applications are completely unaware of one another such as that depicted in Figure 2.

Figure 2. Two loosely-coupled applications using JMS messaging to communicate

Two loosely-coupled applications using JMS messaging to communicate

Application one in Figure 2 sends a message to the MOM in a one-way fashion. Then, possibly sometime later, application two receives a message from the MOM, in a one-way fashion. Neither application has any knowledge that the other even exists and there is no timing interdependence between the two applications. This one-way style of interaction results in much lower maintenance because changes in one application have little to no effect on the other application. For these reasons, loosely coupled applications offer big advantages over tightly coupled architectures when considering distributed application design. This is where ActiveMQ enters the picture.

Think about the changes necessary when an application must move to a new location. This can happen when new hardware is necessary or the application needs to be moved. With a tightly coupled system design, such movement is difficult because all segments of the application must experience an outage. With an application designed using loose coupling, different segments of the system can be moved independent of one another. Consider a scenario where there are multiple instances of application one and multiple instances of application two, where each instance resides on different machines. ActiveMQ is installed on still another machine independent of either application one or application two. In this scenario, any one of the application one or application two instances can be moved around without affecting one another. In fact, multiple instances of ActiveMQ can be used in what's known as a network of brokers configuration which would allow the ActiveMQ instances to be moved around without affecting either application one or application two. This means that any segment of this architecture can be taken down for maintenance at any time without taking down the entire system.

So ActiveMQ provides an incredible amount of flexibility in application architecture and for the concepts surrounding loose coupling to become a reality. But when should ActiveMQ be used to introduce these benefits?

When to Use ActiveMQ

There are many occasions where ActiveMQ and asynchronous messaging can have a meaningful impact on a system architecture. Here are just a few example scenarios:

Heterogeneous application integration - The ActiveMQ broker is written in Java so naturally a Java client API is provided. But ActiveMQ also provides clients for C/C++, .NET, Perl, PHP, Python, Ruby and a few other languages. This is a huge advantage when considering how you might integrate applications written in different languages on different platforms. In cases such as this, the various client APIs make it possible to send and receive messages via ActiveMQ no matter what language is used. In addition to the cross-language capabilities provided by ActiveMQ, the ability to integrate such applications without the use of remote procedure calls (RPC) is definitely a big benefit because messaging truly helps to decouple the applications.

As a replacement for RPC - Applications using RPC style synchronous calls are very widespread. Consider that the vast majority of client-server applications use RPC including ATMs, most web applications, credit card systems, point-of-sale systems and many, many more. Even though many of these systems are very successful, conversion to the use of asynchronous messaging can bring about many benefits without giving up the guarantee of a response. Systems that rely upon synchronous requests typically have a limited ability to scale because eventually requests will begin to back up, thereby slowing the whole system. Instead of experiencing this type of a slow down, using asynchronous messaging, additional message receivers can be easily added so that messages are consumed concurrently and therefore handled faster. This, of course, assumes that your applications can be decoupled.

To loosen the coupling between applications - As already discussed, tightly coupled architectures can be problematic for many reasons, especially if they are distributed. Loosely coupled architectures, on the other hand, exhibit fewer dependencies making them better at handling unforeseen changes. Not only will a change to one component in the system not ripple across the entire system, but component interaction is also dramatically simplified. Instead of using a synchronous scheme for component interaction (where one method calls another and the caller waits for a response from the callee), components utilize asynchronous communications (where they simply send a message without waiting for a response - also known as fire-and-forget). Such loose coupling throughout a system can lead to what is known as an event-driven architecture (EDA).

As the backbone of an event-driven architecture - The decoupled, asynchronous style of architecture described in the previous point allows the software itself to scale much further (known as horizontal scalability) instead of only relying upon the ability of the hardware to scale (known as vertical scalability). Consider an incredibly high-traffic, e-commerce site such as Amazon. When a user makes a purchase on Amazon there are many separate stages through which that order must travel including order placement, invoice creation, payment processing, order fulfillment, shipping and more. However, when a user actually places an order, the user is immediately taken to a page stating, 'Thanks for your order'. Not only that but, without delay, the user also receives an email stating that the order was received. The order placement process that is employed by Amazon is a good example of the first stage in a much larger set of asynchronous processes. Each stage of the order is handled discretely by a separate service. When the user places the order there is a synchronous call to submit the order, but the entire order process does not take place behind a synchronous call via the web browser. Instead, the order is accepted and acknowledged immediately. The rest of the steps in the process are handled asynchronously. If a problem occurs that prevents the process from proceeding, the user is notified via email. Such asynchronous processes are what afford massive scalability and high availability.

To improve application scalability - Many applications utilize an event-driven architecture in order to provide massive scalability including such domains as e-commerce, government, manufacturing and online gaming just to name a few. By separating an application along lines in the business domain using asynchronous messaging, many other possibilities begin to emerge. Consider the ability to design an application using a service for a specific task. This is the backbone of service-oriented architecture (SOA). Each service fulfills a discrete function and only that function. Then applications are built through the composition of these services and the communication among services is achieved using asynchronous messaging and eventual consistency. This style of application design makes it possible to introduce such concepts as complex event processing (CEP). Using CEP, the interactions among the components in a system are tracked for further analysis. Such possibilities are truly endless when you consider that asynchronous messaging is simply adding a level of indirection between components in a system.


Tomcat is extremely popular and so is ActiveMQ. Given Tomcat's runtime capabilities and the wide variety of uses for ActiveMQ, it only makes sense to explore the integration of these two technologies. In this article, you learned a bit about how Java Servlets came about and about how ActiveMQ can help to use loose coupling in your applications. You were also introduced to some use cases for ActiveMQ. Hopefully this background on ActiveMQ is enough to whet your appetite and encourage you to learn more about ActiveMQ.

In the next two articles, you will learn about the two styles of integration that are available in Tomcat and how ActiveMQ can utilize both styles for different benefits.

Bruce Snyder is a veteran of enterprise software development and a recognized leader in open source software. With nearly 15 years of experience, Bruce has worked with a wide range of technologies including Java EE, enterprise messaging and service oriented integration.

In addition to his role as a senior software engineer at SpringSource working on the vFabric Cloud Application Platform, Bruce is also an Apache Member, a co-founder of Apache Geronimo and a developer for Apache ActiveMQ, Apache Camel and Apache ServiceMix. He is a published author, currently co-authoring ActiveMQ In Action for Manning Publications.

Bruce also serves as a member of various JCP expert groups and is a recognized international speaker at industry conferences. Bruce lives in beautiful Boulder, Colorado with his family.


Configuring Active MQ

Hi Bruce. I am trying to build a payment system based around ActiveMQ. I wanted to know if it is a suitable application to use. I have worked with Websphere MQ. The cost of using Websphere MQ is too high at this stage. - Harry

I wanted to thank you for

I wanted to thank you for this excellent read! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. kunststof schuifpuien


I have to voice my passion for your sharpness in writing and giving acknowledges to people. The post should have magnificent guidance on this 55 and over



Thanks for sharing the info, keep up the good work going.... I really enjoyed exploring your site. good resource... Nigeria News



wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. sea view hotel paros



I was just browsing through the internet looking for some information and came across your blog. cool stuff to buy



It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information. anunturi united kingdom



no deposit casino codes



I decided to be here because I have heard that all the articles written were incredible. cheats for my singing monsters


I came across these records

I came across these records interesting in addition to helpful. Find some good interesting solutions AT


This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. clubflyer


I prefer merely excellent

I prefer merely excellent resources - you will see these people in: escorts en curico

Can nicely write on similar

Can nicely write on similar topics! Welcome to here you'll find out how it should look. escorts en punta arenas

I also wrote an article on a

I also wrote an article on a similar subject will find it at write what you think. escorts en antofagasta

I might suggest solely

I might suggest solely beneficial in addition to trusted facts, and so find it: escorts en santiago

Mmm.. estimable to be here in

Mmm.. estimable to be here in your report or notify, whatever, I repute I should moreover process strong for my have website want I play some salubrious further updated busy in your location. The Bonding Code Review


I think that everything has been described in systematic manner so that reader could get maximum information and learn many things. . cheap car insurance companies



I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work best testosterone pills



Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the best! professional link building services



My friend mentioned to me your blog, so I thought I’d read it for myself. Very interesting insights, will be back for more! professional seo company



Good to become visiting your weblog again, it has been months for me. Nicely this article that i've been waited for so long. homes for sale online


this is really nice to

this is really nice to read..informative post is very good to read..thanks a lot!
serum tri mun serumkieu

I can see that you are an

I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business.

This is a great inspiring

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.


Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.

I am happy to find your

I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.
new futura price list

I am really loving the

I am really loving the theme/design of your web site. Do you ever run into any browser compatibility problems? A small number of my blog audience have complained about my site not working correctly in Explorer but looks great in Safari. Do you have any ideas to help fix this problem? 3 week diet foods

I’ve been thinking about

I’ve been thinking about writing a very comparable post over the last couple of weeks, I’ll probably keep it short and sweet and link to this instead if that's cool. Thanks. rebelmouse

I am really enjoying reading

I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work. see these ab workouts

The debate over the number of

The debate over the number of uninsured and whether or not they should be covered, public vs. private insurance, and who pays for all of this will go on. metabolic cooking pdf rebelmouse

Before advancement of Java

Before advancement of Java Servlets, developing web applications designed doing CGI (Common Entry Interface) development. Although CGI is a powerful system, it also comes with some drawbacks. Although some technology came about to deal with some of problems, Java Servlets became a much better substitute. Servlets provide better performance, flexibility, reliable exception to this rule handling, the ability to deal with sessions, a reliable protection design and much more. Servlets very subjective away low-level functions such as techniques, electric electrical sockets, discussions, etc. allowing you to focus on content management. In inclusion to these wide range advantages here are the findings , servlets in inclusion provide standardization in both the API and the overall look. Because of this, as long as a given servlet abides by the specifications, it should run just outstanding in any servlet program.

Before development of Java

Before development of Java Servlets, developing web applications designed click here, doing CGI (Common Accessibility Interface) development. Although CGI is a powerful program, it also comes with some drawbacks. Although some technology came about to handle some of problems, Java Servlets became a much better substitute. Servlets have better performance,

Zuckerpaste Sugaring Paste kaufen im Shop Haarentfernung mit den

Hi there, I discovered your blog per Google bit searching for such kinda educational advise moreover your inform beholds very remarkable for me.
shellac berlin

"Binary Interceptor" - Make $58,736.44 Every Week With This...

Cool you write, the information is very good and interesting, I'll give you a link to my site.
Binary Interceptor Scam

I liked your site. Web

I liked your site. Web designing is an overwhelming and an intimidating task. We have to always consider that facts, which makes your website able to be seen. Likely, it is supposed to be client-friendly. So that, web design denver they can design the websites in a superior way, after culminating, essential features of a site with customer requirements.

thanks for j sharing with

thanks for j sharing with that awesome articles thanks u a lot
rasoio elettrico | regolabarba | ferro da stiro con caldaia | Friggitrice ad Aria | scopa a vapore | ripetitore wifi | ripetitore wifi amplificatore wifi piastra a vapore | miglior aspirapolvere | skateboard elettrico | passeggino leggero | miglior smartphone | tablet per bambini gnhyyt

With so many books and

With so many books and articles coming up to give gateway to make-money-online field and confusing reader even more on the actual way of earning money, Hubwit is a refreshing change. f4x 4 exercises at rebelmouse

TRUTH About PhenQ: Reviews, Ingredients, Side Effects

It is extremely excellent, yet go through the details as of this deal with.
Best Diet Pills In 2016 That Work Fast

I'm seeking to help make

I'm seeking to help make persons obtaining interesting along with educational subject matter, like you can obtain many you will come . rebelmouse

Get the dissertation writing

Get the dissertation writing service students look for these days with the prime focus being creating a well researched and lively content on any topic.

Hi Bruce. I am trying to

Hi Bruce. I am trying to build a deal system based around ActiveMQ official source. I desired to know if it is a appropriate system to use. I been applied with Websphere MQ. The cost of using Websphere MQ is too excellent at this stage. - Harry

I don’t have time to go

I don’t have time to go through it all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the awesome job. 3 week diet @ rebelmouse

I found Hubwit as a

I found Hubwit as a transparent s ite, a social hub which is a conglomerate of Buyers and Sellers who are ready to offer online digital consultancy at decent cost. mi40x @ rebelmouse

The first thing to visit this

The first thing to visit this blog is useful information and add our insight and knowledge for us all thank you admin rebelmouse

I am not sure the things that

I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.

Greetings! I know this is

Greetings! I know this is kinda off topic nevertheless I'd figured I'd ask. Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa?

You can learn how to

You can learn how to introduce the stats of a thing to note. There are many ways you can take but you have to find the right and best.

My rather long internet look

My rather long internet look up has at the end of the day been compensated with pleasant insight to talk about with my family and friends. red smoothie detox at

This subject has interested

This subject has interested me for quite some time. I have just started researching it on the Internet and found your post to be informative.

Get Healthy why such

Get Healthy

why such information is for free here? Because when you write a book then at least on selling a book you get a percentage. Thank you and good luck on informing people more about it

Post new comment

This question is for testing whether you are a human visitor and to prevent automated spam submissions.