Search code examples
javasessiontomcattomcat7session-cookies

Session Replication in Tomcat


We have two separated servers and configured with Delta session manager to replicate session between two servers. The replication between them was successful and if I down any one of the server it works fine, but it always shows an error at catalina.out that

object are not serialized


Solution

  • In case of Apache Tomcat 7 we can uncomment <Cluster className=”org.apache.catalina.ha.tcp.SimpleTcpCluster”/> tag and update cluster detail something liek below.

    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
        <Manager className="org.apache.catalina.ha.session.DeltaManager"
            expireSessionsOnShutdown="false"        
            notifyListenersOnReplication="true"/>
        
        <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        
            <Membership className="org.apache.catalina.tribes.membership.McastService"
            address="228.0.0.4"
            port="45564" frequency="500"
            dropTime="3000"/>           
    
            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">                
                <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>              
            </Sender>           
            
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
            address="auto" port="4000" autoBind="100"
            selectorTimeout="5000" maxThreads="6"/>                     
            
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>         
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>   
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>                      
        
        </Channel>
        
        <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" />       
        <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />       
        
    </Cluster>
    

    Also, we need to add workers.properties at apache/conf/ path.

    Please note this file has to be placed in all the Tomcat servers which will run in a cluster.

    You can read more in detail here.