I've managed to write both an AJAX and a JAVA JMS client (in this case for ActiveMQ's JMS broker). Each have been working to consume and produce JMS messages as separate projects, unfortunately though, trying to run them in the same project does not work (possibly because of my own misunderstanding of Tomcat's limitations as a J2EE container). What I'm trying to do is have the JAVA client act as an "always-on" listener for when the AJAX JMS client is not listening (i.e. browser is closed). When a browser client opens, the (constantly running) JAVA client can ignore the messages... but... when no browser client is initialized, the JAVA client should respond to the messages on behalf of the AJAX client.
I've tried using a ServletContextListener
pattern, which I was hoping would launch the JAVA listener via its main method, whenever the Servlet gets initialized (i.e. it would auto-start when Tomcat gets restarted, or, anytime the Servlet gets redeployed) but it seems Tomcat is not thread-safe and this might be causing some problems. In any case, I can't seem to get the JAVA client to reliably start running and stay running for the lifetime of my AJAX client (webapp .war), and without including them in the same project and same J2EE container sharing the same ServletContext, I don't know how its possible to ensure they are running, starting and stopping at the same time.
If anyone knows a solution for running AJAX and JAVA JMS connectors together, please share...