Hi Folks,

I'm in the process of implementing 'Tomcat session replication using Caching
<https://redmine.wso2.com/issues/2816>' [1]. But I've found a very
interesting approach to achieve it out of the box using Hazelcast.

Hazelcast WM allows us to cluster user http sessions automatically.
Followings are required for enabling Hazelcast Session Clustering
<http://hazelcast.com/use-cases/web-session-clustering/> [2][3]

   - Target application or web server should support Java 1.5+
   - Target application or web server should support Servlet 2.4+ spec
   - Session objects that needs to be clustered have to be Serializable

Purpose of web session clustering is to replicate web session state across
a distributed application servers. Benefits, allow us to scale out  but
also avoid any single point of failure and allow us to dynamically handle
node failure within the application tier. performance of this web session
clustering is high according to VP Hazelcast
<https://www.youtube.com/watch?v=8a0LrlOIXq0>. Using Hazelcast session
replication can be achieved in two different ways. Observations as follows.

   - *Hazelcast Enterprise* has native web session clustering build in to
   Apache Tomcat.
   - *Opensource Hazelcast* has provide a web session clustering as an
   external filter, basically Hazelcast filter has to be placed before all of
   other filters and that will enable us to provide the web session clustering
   in opensource. In this use case it doesn't required changes to application
   itself. Example as follows,

*web.xml edit*, Make sure Hazelcast filter is placed before all the other
filters if any

<filter>

    <filter-name>hazelcast-filter</filter-name>

    <filter-class>com.hazelcast.web.WebFilter</filter-class>

    <!–

        Name of the distributed map storing

        your web session objects

    –>

    <init-param>

        <param-name>map-name</param-name>

        <param-value>my-sessions</param-value>

    </init-param>

    <!– How is your load-balancer configured? stick-session means all
requests of a session is routed to the node where the session is first
created. This is excellent for performance. If sticky-session is set to
false, when a session is updated on a node, entry for this session on all
other nodes is invalidated. You have to know how your load-balancer is
configured before setting this parameter. Default is true. –>

    <init-param>

        <param-name>sticky-session</param-name>

        <param-value>true</param-value>

    </init-param>

    <!–

        Are you debugging? Default is false.

    –>

    <init-param>

        <param-name>debug</param-name>

        <param-value>true</param-value>

    </init-param>

</filter>

<filter-mapping>

    <filter-name>hazelcast-filter</filter-name>

    <url-pattern>/*</url-pattern>

    <dispatcher>FORWARD</dispatcher>

    <dispatcher>INCLUDE</dispatcher>

    <dispatcher>REQUEST</dispatcher>

</filter-mapping>

<listener>

    <listener-class>com.hazelcast.web.SessionListener</listener-class>

</listener>


All http requests will go through Hazelcast Web Filter and it will put the
session objects into Hazelcast distributed map if needed. So WDYT?

Please advice as to how I should go about handling this.

[1] https://redmine.wso2.com/issues/2816
[2] http://hazelcast.com/use-cases/web-session-clustering/
[3] http://hazelcast.org/docs/latest/manual/html/httpsessionclustering.html
[4] https://www.youtube.com/watch?v=8a0LrlOIXq0
​

-- 
*Pubudu Dissanayake*
 Software Engineer

WSO2 Inc.; http://wso2.com
lean.enterprise.middleware
Mob: + 94 775 503 304

Blog: http://geekdetected.wordpress.com/
Linkedin: *http://lk.linkedin.com/in/pubududissanayake*
<http://lk.linkedin.com/in/pubududissanayake>
Flickr : https://www.flickr.com/photos/pubudufx/
Twitter: https://twitter.com/GeekInAction
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to