0

I use Spring Boot 3.x and an external Tomcat 10. Set up session clustering on an external Tomcat If I check on the jsp page, the session is shared, but If I check the same logic with spring boot service, the session is not being shared. If I check with jsp, it seems to be shared, so session clustering between external Tomcats is not possible. It seems like it's set up, but why can't it be shared in Spring Boot? SpringBootServletInitializer has already been implemented.

I am testing with two different Tomcat ports locally on Windows. Distributable="true" is set in Context.

@GetMapping("/session-test")
public String sessionTest(HttpSession session, Model model) {

   log.info("sessionTest  enter ");

    String sessionId = session.getId();
    Integer counter = (Integer) session.getAttribute("counter");
    if (counter == null) {
        counter = 1;
    } else {
        counter++;
    }
    session.setAttribute("counter", counter);

    model.addAttribute("sessionId", sessionId);
    model.addAttribute("counter", counter);

    return "web/sessionTest"; 
}

Two Spring Boot servers want their sessions to be shared ...

server.xml of 1

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
      
        <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
            <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Manager className="org.apache.catalina.ha.session.DeltaManager"
               expireSessionsOnShutdown="false"
               notifyListenersOnReplication="true"/>
                <Receiver 
                    address="127.0.0.1" 
                    port="3200" 
                    autoBind="100" 
                    selectorTimeout="5000"
                    maxThreads="6" 
                    className="org.apache.catalina.tribes.transport.nio.NioReceiver"/>

                <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                    <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
                </Sender>

                
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
                
                
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
                    <Member className="org.apache.catalina.tribes.membership.StaticMember" 
                            host="127.0.0.1" 
                            port="3201" 
                            uniqueId="{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}"/>
                </Interceptor>

                <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>
            </Channel>

            <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"/>
            <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
        </Cluster>

  <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="ROOT" distributable="true"/>
    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

server.xml of 2

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
        <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">
                
                <Receiver 
                    address="127.0.0.1" 
                    port="3201" 
                    autoBind="100" 
                    selectorTimeout="5000"
                    maxThreads="6" 
                    className="org.apache.catalina.tribes.transport.nio.NioReceiver"/>

                <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
                    <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
                </Sender>

                
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
                
                
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
                    <Member className="org.apache.catalina.tribes.membership.StaticMember" 
                            host="127.0.0.1" 
                            port="3200" 
                            uniqueId="{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17}"/>
                </Interceptor>

                <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>
            </Channel>

            <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"/>
            <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
        </Cluster>
        
        <Host name="localhost"  appBase="webapps"  unpackWARs="true" autoDeploy="true">
        <Context path="" docBase="ROOT" distributable="true"/>
2
  • What have you done to set this up. Please share some configuration (as apparently that is where the problem is). Commented Sep 18, 2024 at 13:31
  • I have registered additional settings. Commented Sep 22, 2024 at 0:56

1 Answer 1

0

I handled it like this...... I don't know why I have to do this.

<Context>
    <Manager className="org.apache.catalina.ha.session.DeltaManager"/>
</Context>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.