{"id":1374,"date":"2010-07-22T20:15:49","date_gmt":"2010-07-22T14:45:49","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1374"},"modified":"2014-05-06T13:44:34","modified_gmt":"2014-05-06T08:14:34","slug":"tomcat-6-in-memory-session-replication","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/tomcat-6-in-memory-session-replication\/","title":{"rendered":"Tomcat 6 in-memory session replication"},"content":{"rendered":"<p>Hi All,<\/p>\n<p>Here are the few basic steps that you need to follow in order to achieve the in-memory session replication between two or more Tomcat 6 instances. <\/p>\n<p>This blog refers the Apache Tomcat documentation as found here: <a href=\"http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/cluster-howto.html\" target=\"_blank\">http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/cluster-howto.html<\/a>.<br \/>\nThe Tomcat documentation provides more detailed explanation of the Clustering concepts as well as the definition of tags, attributes etc. used in <strong>server.xml<\/strong> file.<\/p>\n<p><strong>Step 1:<\/strong> Include the <strong>&lt;distributable&gt;<\/strong> tag in <strong>web.xml<\/strong> file i.e. you can simple write the following line in your deployment descriptor(i.e. web.xml):<\/p>\n<blockquote>\n<pre lang=\"groovy\">\r\n <distributable \/> \r\n<\/pre>\n<\/blockquote>\n<p>Please read the following link to know more about this tag: <a href=\"http:\/\/wiki.metawerx.net\/wiki\/Web.xml.Distributable\" target=\"_blank\">http:\/\/wiki.metawerx.net\/wiki\/Web.xml.Distributable<\/a><\/p>\n<p><strong>Step 2:<\/strong> Add the following lines of XML in the <strong>server.xml<\/strong> file inside the <strong>&lt;Engine&gt;<\/strong> element\/tag:<\/p>\n<blockquote>\n<pre lang=\"groovy\">\r\n<Engine name=\"Catalina\" defaultHost=\"localhost\">\r\n      <Cluster className=\"org.apache.catalina.ha.tcp.SimpleTcpCluster\"\r\n            channelSendOptions=\"8\">\r\n                     <Manager className=\"org.apache.catalina.ha.session.DeltaManager\"\r\n                      expireSessionsOnShutdown=\"false\" notifyListenersOnReplication=\"true\"\/>\r\n                     <Channel className=\"org.apache.catalina.tribes.group.GroupChannel\"> \r\n                               <Membership className=\"org.apache.catalina.tribes.membership.McastService\" \r\n                               address=\"228.0.0.4\" port=\"45564\" frequency=\"500\" dropTime=\"3000\"\/> \r\n                              <Receiver className=\"org.apache.catalina.tribes.transport.nio.NioReceiver\" \r\n                                 address=\"auto\" port=\"4000\" autoBind=\"100\" selectorTimeout=\"5000\" maxThreads=\"6\"\/>\r\n                               <Sender className=\"org.apache.catalina.tribes.transport.ReplicationTransmitter\"> \r\n                                             <Transport className=\"org.apache.catalina.tribes.transport.nio.PooledParallelSender\"\/> \r\n                                <\/Sender>\r\n                      <Interceptor className=\"org.apache.catalina.tribes.group.interceptors.TcpFailureDetector\"\/>\r\n                      <Interceptor className=\"org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor\"\/>\r\n                  <\/Channel>\r\n           <Valve className=\"org.apache.catalina.ha.tcp.ReplicationValve\" filter=\"\"\/> \r\n          <Valve className=\"org.apache.catalina.ha.session.JvmRouteBinderValve\"\/> \r\n          <Deployer className=\"org.apache.catalina.ha.deploy.FarmWarDeployer\" \r\n                   tempDir=\"\/tmp\/war-temp\/\" deployDir=\"\/tmp\/war-deploy\/\" watchDir=\"\/tmp\/war-listen\/\"\r\n                   watchEnabled=\"false\"\/> \r\n                   <ClusterListener className=\"org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener\"\/>\r\n                  <ClusterListener className=\"org.apache.catalina.ha.session.ClusterSessionListener\"\/>\r\n     <\/Cluster>\r\n .\r\n .\r\n .\r\n .\r\n <\/Engine>\r\n <\/pre>\n<\/blockquote>\n<p>Please note that there might be some other elements such as <strong>&lt;Host&gt;, &lt;Realm&gt; <\/strong>etc. inside the <strong>&lt;Engine&gt;<\/strong> element. Also, for each tomcat instance the value defined for the <strong>&#8216;port&#8217;<\/strong> attribute of the <strong>&lt;Receiver&gt;<\/strong> tag must be unique.<\/p>\n<p>And, that&#8217;s all. You now have a basic session-replication in place. Your sessions are replicated amongst all the tomcat instances which are part of your cluster.<\/p>\n<p><strong>NOTE:<\/strong> Please make sure if you make any changes to the &#8220;<strong>context.xml<\/strong>&#8221; file, you have to delete the following xml file located in the <strong>&lt;TOMCAT_HOME&gt;\/conf\/Catalina\/localhost\/{yourAppName}.xml<\/strong>. If you don&#8217;t delete this file, then your changes will be ignored and the settings defined in this file will take effect.<\/p>\n<p>Cheers!!!<\/p>\n<p>Abhishek Tejpaul<br \/>\nabhishek@intelligrape.com<br \/>\n[Intelligrape Software Pvt. Ltd.]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi All, Here are the few basic steps that you need to follow in order to achieve the in-memory session replication between two or more Tomcat 6 instances. This blog refers the Apache Tomcat documentation as found here: http:\/\/tomcat.apache.org\/tomcat-6.0-doc\/cluster-howto.html. The Tomcat documentation provides more detailed explanation of the Clustering concepts as well as the definition [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[1],"tags":[591,593,590,592,17,589],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1374"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1374"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1374\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}