File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Very simple JMS ActiveMQ PTP interaction on Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Very simple JMS ActiveMQ PTP interaction on Tomcat" Watch "Very simple JMS ActiveMQ PTP interaction on Tomcat" New topic

Very simple JMS ActiveMQ PTP interaction on Tomcat

Anthony Rowlands

Joined: Dec 09, 2010
Posts: 5
I'm very new to Tomcat and JMS, but I would like to do the following:

1. Send POST to servlet from a web form (I have this working)

2. Have the servlet send a message to a JMS queue (PTP) (I want ActiveMQ running within Tomcat here)

3. Have a separate Java process listen to the queue and consume the message (PTP)

Pretty simple yes? I'm having a lot of trouble because there is a seemingly infinite amount of configuration to do with Tomcat, ActiveMQ, JNDI, etc etc. I can't swallow the tutorials out there on the web, because most of them are not for my particular situation (some use Spring, some use Topics not PTP queues, some aren't using ActiveMQ, yada yada). Not to mention the JMS/JNDI API's are scary for a total newbie.

Can anyone point me in the right direction? I can't seem to find a straightforward tutorial for PTP JMS on Tomcat/ActiveMQ for absolute beginners.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

The JMS API sequence in a servlet is basically the same as it would be for a standalone Java application. Getting a separate process to run in response with the JMS request is something that the JMS server has to deal with.

The only major caveat is that the servlet shouldn't be spending a long time waiting for the JMS server to post a response back, since HTTP (including servlets and JSPs) is expected to respond relatively quickly. If the process in question takes a long time, you should offload the JMS request/wait to a background processor rather than attempt to handle it directly in the servlet doPost method.

An IDE is no substitute for an Intelligent Developer.
Bruce Snyder

Joined: Nov 03, 2010
Posts: 10
FWIW, I just wrote a series of articles on the topic of ActiveMQ and Tomcat for the website. The first article in the series was just made available this week:

ActiveMQ and Tomat: Perfect Partners

The example in the article uses an HTML form to post a message to an ActiveMQ queue which is consumed by the Spring message listener container. Pretty simple stuff really. The article provides a brief description of using ActiveMQ and Tomcat which was excerpted from the forthcoming book ActiveMQ In Action which contains much more detail on this topic in chapter 8.

If you have any questions, let me know.

Sonia Rana

Joined: Mar 05, 2012
Posts: 2
Hi Anthony Rowlands,
I am also working on almost same use case:

1. I need to POST data to Tomcat using servlets over HTTP (This is working).
2. Then, need to send and receive messages to ActiveMQ over JMS Queue.
3. ActiveMQ process the message received and send response back.

I dont know how to do the 2nd and third step. I am very new to all. I hope you are done with this usecase upto now. Can you direct me for the configurations neededand steps involved.
Or Is there anyone else can help me out for the same.
Thanks in advance
I agree. Here's the link:
subject: Very simple JMS ActiveMQ PTP interaction on Tomcat
It's not a secret anymore!