javatomcat6hazelcastsession-replication

P2P Hazelcast Session Replication for Tomcat6 Web Clustering - Session Synchronization Fails


I believe I am missing some configuration either on load balancing side or in tomcat, it would great if someone could help and provide the solution.

What am i trying to do?

  1. Setup two tomcat instances with P2P Hazelcast session replication for tomcat6 by referring to this guide
  2. I have placed the hazelcast-all-.jar, hazelcast-tomcat-sessionmanager-.jar and hazelcast.xml in the folder $CATALINA_HOME/lib/
  3. Updated the listener and the context configs as shown below
  4. Updated Tomcat Failover and the jvmRoute Parameter as shown below
  5. So far, i was able to bring up the tomcat instances which connect to each others hazelcast instances, I see that in the tomcat logs.
  6. The users connects to the load balancer and are routed to the balancer members - no issues here.
  7. But when I take one of the tomcat instance down to test failover and to make sure users who were connected to tom instance were able to continue to cat instance with the same session and without having to sign in again. But I believe the load balancer seems to be creating a new session and forces user to sign in again to establish a session with cat instance. I suspect it this but not sure.
  8. Or are the sessions not being replicated and synced in both hazelcast instances? - This is happening
  9. Do we have a client where I could monitor hazelcast sessions? - Now I do

I did refer to this issue which refers setting up hazelcast.sessionId instead of JSESSIONID but does not provide any specifics about how to.

Versions -

Apache Haus - 2.2.32 (for load balancing)
Hazelcast - 3.8.6
Java 8
Tomcat - 6.0.48
Session objects that need to be clustered are Serializable.
stickysession=JSESSIONID

Load Balancer Configuration

 <Proxy balancer://mycluster>
        BalancerMember http://IPAddress1:8080/app/  route=tom
        BalancerMember http://IPAddress2:8080/app/  route=cat
        ProxySet lbmethod=byrequests stickysession=JSESSIONID|jsessionid
 </Proxy>

    ProxyPass /app/ balancer://mycluster/ 
    ProxyPassReverse /app/ balancer://mycluster/

tom instance - server.xml

<Listener className="com.hazelcast.session.P2PLifecycleListener"/>
<Engine name="Catalina" defaultHost="localhost"  jvmRoute="tom">

tom instance - context.xml

<Manager className="com.hazelcast.session.HazelcastSessionManager" sticky=true/>

cat instance - server.xml

<Listener className="com.hazelcast.session.P2PLifecycleListener"/>
<Engine name="Catalina" defaultHost="localhost"  jvmRoute="cat">

cat instance - context.xml

<Manager className="com.hazelcast.session.HazelcastSessionManager" sticky=true/>

Update:

I believe the below is the same issue I have session sync failure


Solution

  • I got it working with the below configuration. Figured it needed both jsessionid and hazelcast.sessionid, the session replication works great now.

    <Proxy balancer://mycluster>
        BalancerMember http://IPAddress1:8080/app/  route=tom
        BalancerMember http://IPAddress2:8080/app/  route=cat
        ProxySet lbmethod=byrequests stickysession=JSESSIONID|jsessionid|hazelcast.sessionId
    </Proxy>
    
    ProxyPass /app/ balancer://mycluster/ 
    ProxyPassReverse /app/ balancer://mycluster/