Why is Tomcat session replication not working?
Have you added the magic </distributable> element to the top of your web application’s web.xml?
How nodes in the cluster are identified
Tomcats in the cluster identify themselves on a multicast address
So you should see an entry in each tomcat’s catalina.out, for every other tomcat which joins the cluster.
If this is working, it is likely that your multicast setup for the cluster is functioning OK, and the tomcats know about one another.
So the problem must be to do with replicating the session information within the cluster after each request, which takes place via TCP
How session data is replicated
Check your </distributable> tag in the web.xml again.
Unless this is there, the cluster will not even try to replicate the session information for the web app.
By the way, the default jsp-examples web app does not have the distributable tag set up by default – you have to add it if you want to use jsp-examples for testing
Each time the session information is updated, you should see an entry in the localhost.log for each tomcat in the cluster, indicating that the session attributes have been added
How to test it is working
Well you can use the cart example in the jsp-examples web app to check that the cart contents still remain after you kill tomcats in the cluster.
Here is a JSP you can also use, which shows the host you are connected to and the session id
<html>
<body>
<h1><font color="red">Session serviced by <%= java.net.InetAddress.getLocalHost().getHostName() %></font></h1>
<table aligh="center" border="1">
<tr>
<td>
Session ID</td>
<td><%= session.getId() %></td>
<% session.setAttribute("abc","abc"); %>
</tr>
<tr>
<td>
Created on</td>
<td><%= new java.util.Date(session.getCreationTime()).toString() %></td>
</tr>
</table>
</body>
</html>
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply