Tomcat Web Session ReplicationWeb Session Replication is replicating web sessions to other members of the cluster each time there is a change in the session data. With session replication, session-failover is automatic. If an application server goes offline, the load balancer sends incoming requests to another server. The user can be sent to any server, as all servers have a copy of the user’s session.
Tomcat Web ServerApache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation (ASF). Tomcat implements several Java Enterprise Edition specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, and provides a “pure Java” HTTP web server environment for Java code to run in.
Hazelcast IMDG and TomcatYou can use Tomcat Web Session Replication with Hazelcast IMDG® version 3.0 or higher. Tomcat Session Replication in Hazelcast IMDG is a Hazelcast® Module where the state of each created HttpSessionObject is kept in the Hazelcast Distributed Map. If you configure with Sticky Sessions, you boost performance because each Tomcat Instance will have its own local copy of the session. Since the sessions are in Hazelcast Distributed Map, you can use all the available features offered by the Hazelcast Distributed Map implementation.
No Lost User SessionsTomcat with Hazelcast IMDG uses web session replication with distributable web applications to provide session-failover and to enable load balancing. Let’s say you have more than one web server (A,B,C) with a load balancer. Once one of the servers goes down, you don’t lose user sessions. Users will be routed to other servers (B or C) and they will not notice something is wrong with Server A. Also, you can scale your web servers under heavy load. You can easily add new servers to your cluster. Sessions will be evenly distributed across the Hazelcast Cluster. You can even shut down servers from the cluster without losing any sessions.
RequirementsThe following are required to enable Hazelcast Session Clustering with Tomcat.
- Tomcat 6, 7, 8 and 8.5 are supported
- The target application or web server should support Java 1.6+
- The target application or web server should support Servlet 3.0+ spec
- The session objects that need to be clustered have to be serializable
Easy to Set UpAn advantage of the Tomcat Session Replication Module for Hazelcast IMDG is that you don’t change anything in your application. You only need to perform some configuration in your Tomcat container to easily attach Hazelcast Session Replication to your web applications. To configure Tomcat for Hazelcast IMDG:
hazelcast.xml (if you want to change defaults) in the folder $CATALINA_HOME/lib/.
- Put a
<Listener>element into the file
$CATALINA_HOME$/conf/server.xmlas shown below.
<Server> ... <Listener className="com.hazelcast.session.P2PLifecycleListener"/> ... </Server>
- Put a
<Manager>element into the file
$CATALINA_HOME$/conf/context.xmlas shown below.
<Context> ... <Manager className="com.hazelcast.session.HazelcastSessionManager"/> ... </Context>