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.