0

I need to enable the session affinity in liberty server. Is it enabled by default or do we have some tags or attributes which can be configured in server.xml file.

P Darius
  • 3
  • 5

1 Answers1

2

If your application makes use of the Java EE HTTP Session API HTTPServletRequest.getSession() then Liberty will emit cookies that allow any HTTP proxy server to maintain affinity without any kind of configuration.

The only pieces that normally require configuration are:

  1. Selecting a custom/persistent HTTP clone ID, also known as a "worker" or "route" name in other environmnets. This can be done with a simple server.xml tag: <httpSession cloneId="foo1"/>
  2. Session persistence, which is related to failover but not affinity, requires significant configuration such as a backing database or memory grid for shared storage.

To confirm session affinity is working:

  1. Start an incognito browser
  2. Access your application
  3. Use browser developer tools or webserver logs to look at incoming or outgoing session cookies
  4. Note the cloneID in the last ':' separated field of the JSESSIONID cookie

If there's no cookie, there's no affinity because there's no session being established. That's an application issue.

If there's a cookie but it doesn't take you back to the right server, it's likely because the cloneID in use at the time the webserver config was generated is no longer in use by the backend application. Pick a persistent cloneID as described above and regenerate/reconfigure.

If you think there's a problem, you need to be able to show at least the session cookie transmitted by the client and the server definition in the webservers plugin-cfg.xml, and the cloneID that shows in the auto-generated logs/state/plugin-cfg.xml on the server you think this request should have affinity to.

covener
  • 17,402
  • 2
  • 31
  • 45
  • @convener can this be achieved if we have multiple standalone liberty servers. Or do we need to cluster the liberty servers. Tks – P Darius Apr 21 '18 at 16:13
  • 1
    Multiple standalone servers is fine, they don't need to be aware of eachother for affinity. – covener Apr 21 '18 at 16:14
  • sorry to bother u. This is how system is I have two liberty server in physical server 122 with application A and B and another server 123 with two liberty server with same A and B as in 122. I have generated the plugin and merged it and then I have once again merged the merged plugin of 122 and 123 and propagated to the IBM http server. With this scenario I am unable to achieve the session affinity. Is there any other configuration I need to do. Tks – P Darius Apr 21 '18 at 16:25
  • I added to my answer, but you have to understand that this site is designed for Q&A about programming topics. This might be more suitable for something like a forum on developerworks. – covener Apr 21 '18 at 16:36