Over a million developers have joined DZone.

Keeping Track of Tomcat Across the Cloud

· Java Zone

Easily build powerful user management, authentication, and authorization into your web and mobile applications. Download this Forrester report on the new landscape of Customer Identity and Access Management, brought to you in partnership with Stormpath.

Keeping your Tomcat application synchronized across the cloud can be a tricky task, but Jon Brisbin has posted an article about his own approach to keeping track of his webapps over at TomcatExpert. For his particular use case, being able to maintain sessions across the cloud is important, in order to meet up with government regulations on audit trails. His solution is composed of some Ruby code, RabbitMQ and JMX:

I approached this problem in our own private cloud by writing a Tomcat LifecycleListener that hooks into our RabbitMQ servers to keep interested queue subscribers updated with the internal state of our SpringSource tcServer instances, as well as providing the ability to invoke JMX MBeans via asynchronous messaging. Since this system uses AMQP, any language that has an AMQP client that can talk to RabbitMQ can invoke JMX-managed MBeans.

RabbitMQ is central to the architecture, and  is brought in so that all of the tcServer instances can communicate with each other for session clustering. A Lifecycle listener is used in each instance to keep track of the state on all nodes, using the built-in Tomcat lifecycle events. As JMX related messages come in, they are published onto specific queues. Ruby code is used to handle the lifecycle events, with another subscriber implemented in Ruby handling JMX messages. 

This simple approach gives a lot of power: 

In just a few lines of Ruby code, we've created a very usable utility to monitor cloud services availability. You could insert a record into your NoSQL database or interrogate the JVM and calculate load balancer weights. You could deploy an application onto that server, now that it's available. I'm using this to create an uber-lightweight management and monitoring application to help me keep all these servers corralled and running smoothly.



The Java Zone is brought to you by Stormpath—a complete, pre-built User Management API. Want to learn how to use JWTs to protect microservices from CSRF and more? Check out this on-demand webinar with our Java Developer Evangelist, Micah Silverman.


Published at DZone with permission of James Sugrue, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}