Session Replication in Payara Server with Hazelcast

Uncategorized

*Note: This blog post is an update to Dynamic Clustering and Failover on Payara Server With Hazelcast, which was written for Payara Server 4.

Introduction

This article continues our introductory blog series on setting up a simple deployment group with Payara Server, carrying straight on from our last blog where we configured sticky sessions for Payara Server.

If you have been following this series, so far we have:

This works quite well so far, and presuming your servers are the electronic equivalent of Wolverine and never die, that’s all good. If however, like the rest of us, you anticipate a server at some point needing to go down, you might wonder what will happen to any active sessions on that instance. Using the ‘sticky session’ approach from the last blog post will mean that when a server goes down, all session data is lost. This is a problem for most applications. To prevent this, you can use ‘session replication’ to ensure that there is always another instance with a copy of the session data from any other instance. This means that from a user’s perspective, it will be nearly impossible to tell when a server goes down. This provides several benefits, not least of which is the ability to perform a rolling upgrade on instances one at a time with no downtime. This blog will demonstrate how to enable session replication, to allow this functionality.

Web Container Availability

In order to allow session replication, web container availability must first be enabled. This allows web container managed properties such as sessions to be shared across instances with the same configuration.

 

With your instances started and referencing the same config, any change made to the shared config (in this case dg-config) will apply to both of our instances (as well as any other instances we create which reference dg-config). Previously in Payara Server 4, you had to enable Hazelcast and configure availability manually. This is all configured by default in Payara 5. In case you’ve changed any of the configuration, check that the availability service is enabled and the persistence type is ‘hazelcast’ in the Web Container Availability page:

 

Screen Shot 2018-08-08 at 2.39.03 PM

Application Distributable Tag

The Servlet 3.1 specification defines a tag for the application web.xml (in src/main/webapp/WEB-INF). This tag is the <distributable/> tag. It is defined as follows:

Screen Shot 2018-08-08 at 2.39.47 PM

Once this tag is included, your application will be marked as being appropriate to be deployed in a distributed Servlet container. In the context of a deployment group deployed application, it allows sessions to be replicated.

 

Serialisation

Configuration wise, the above steps should be all you need to get session replication working. However, replication requires that the user session be serialisable (to send to the other instances). If you’re storing objects in your session, make sure that each of these objects is serialisable. To do this make sure that all objects as well as each of their fields either directly or indirectly implements the Serializable interface.

 

Need Help Using Payara Server? Learn About Our Support Options:

{{cta(‘2701aff7-585c-4b76-b77f-32ee1b11c47a’)}}

 

 

Comments (7)

Post a comment

Your email address will not be published. Required fields are marked *

Payara needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at any time. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, please review our Legal & Privacy Policy.

  1. Julie Page

    Hi, I can’t get the session replication to work within Payara. I have been following the blog and followed the steps above but when I check the Availability check box within a deployed application, a success message is displayed but a java.lang.RuntimeException is logged in the log file and the application becomes not available. Any suggestions?

  2. Matt Gill

    Hi Julie,

    For issues such as this I would recommend raising an issue on our GitHub: https://github.com/payara/Payara/issues. If you post the exact exception you get, reproducer steps as well as the Payara Server version you’re using, we’ll try and help as best we can!

    Kind regards,

    Matt

  3. Sachin G

    I want to enable sticky session on SLB AX-3200-12. What would be the Payara settings with this LB?

    1. Matthew Gill

      Hi Sachin,

      Have you read the previous blog in the series? You can find it here: https://www.payara.fish/blog/configuring-sticky-sessions-for-payara-server-with-apache-web-server-1. If you have any issues feel free to ask questions in our forum: https://groups.google.com/g/payara-forum/ or on our Github: https://github.com/payara/Payara.

      Best regards,

      Matt

  4. Yasher Mahmood

    Hi Matthew,

    I want to Monitor the Hazelcast after Session Replication in Payara Server. I want to check what is getting stored as cookies, read/write, etc. Can you tell me how that can be done, I know just that we can check for Cache-keys and list caches using asadmin commands. Can help me how I can get more information.

  5. Darko Vasilev

    One very, very, very important thing that is skipped in this tutorial is to tick the Availability checkbox when deploying the application to the deployment group. Without it session replication won’t work

  6. Mausam Shrestha

    Is session replication only allowed via deployment groups. I am trying to enable session replication in a openshift deployment, where payara server instances form a hazelcast cluster through multicast.

Related Posts

4 minutes
Uncategorized

Leading the Way: Payara Platform Community 7 Beta Now Fully Jakarta EE 11 Certified

We’re excited to announce that Payara Platform Community 7 Beta application server is now fully certified as Jakarta EE 11 […]

What Is a Java Application Server? A Short Guide 6 minutes
Jakarta EE

What Is a Java Application Server? A Short Guide

Enterprise Java applications power global commerce, healthcare, government and countless other industries. These systems must be scalable, secure and […]

10 minutes
Uncategorized

Java’s 30th Anniversary: A Celebration of Legacy, Evolution and Community

May 2025 marks a monumental milestone in software development: Java turns 30. The impact of this language on the […]