AWS ECS session replication

Hi,

I’m trying to set up a data grid on AWS ECS.

I was able to get JCache working with these tutorials:

But session replication is not working. I developed a very simple JSF webapp to test based on the hajspcluster demo, it has on web.xml and the session attributes are serializable.

What am I missing?

Thanks

Session test application code:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
   <h:head>
      <title>Facelet Title</title>
   </h:head>
   <f:view transient="true">
      <h:body>
         <h:form id="form">
            Key <h:inputText value="#{indexBean.key}" />
            Value <h:inputText value="#{indexBean.value}" />
            <h:commandButton value="add" action="#{indexBean.add()}" />
            <br /><br />
            <ul>
               <li>server: <h:outputText value="#{facesContext.externalContext.request.serverName}" /></li>
               <li>session id: <h:outputText value="#{facesContext.externalContext.request.session.id}" /></li>
               <li>Served From Server instance: #{indexBean.instanceName}</li>
               <li>Executed Server IP Address: #{indexBean.hostAddress}</li>
            </ul>
            <br /><br />
            <ui:repeat id="itens" value="#{indexBean.sessionMap}" var="item">
               #{item.key} - #{item.value} <br />
            </ui:repeat>
         </h:form>      
      </h:body>
   </f:view>
</html>
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template
 */
package com.mycompany.session.test;

import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.net.UnknownHostException;
import java.util.Map;
import javax.faces.context.FacesContext;

/**
 *
 * @author fjaekel
 */
@Named(value = "indexBean")
@SessionScoped
public class IndexBean implements Serializable {

   private String key;
   private String value;
   
   /**
    * Creates a new instance of IndexBean
    */
   public IndexBean() {
      
   }
   
   public void add()
   {
      getSessionMap().put(key, value);
      
      System.out.println(getSessionMap());
   }
   
   public String getInstanceName()
   {
      return System.getProperty("com.sun.aas.instanceName");
   }
   
   public String getHostAddress()
   {
      try {
         return java.net.InetAddress.getLocalHost().getHostAddress();
      } catch (UnknownHostException ex) {
        return ex.getMessage();                
      }
   }

   public String getKey() {
      return key;
   }

   public void setKey(String key) {
      this.key = key;
   }

   public String getValue() {
      return value;
   }

   public void setValue(String value) {
      this.value = value;
   }

   public Map<String, Object> getSessionMap() {
      return FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
   }   
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
   
    <distributable/>
    
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
      <param-value>client</param-value>       
    </context-param>
    
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    
    <session-config>
        <session-timeout>
            30
        </session-timeout>
        <!--<tracking-mode>COOKIE</tracking-mode>-->
    </session-config>
    
    <welcome-file-list>
        <welcome-file>index.jsf</welcome-file>
    </welcome-file-list>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
   <session-config>
      <session-manager persistence-type="hazelcast"> 
         <manager-properties>
            <property name="relaxCacheVersionSemantics" value="true"/>
         </manager-properties> 
      </session-manager> 
   </session-config>
</glassfish-web-app>

HI @fkj,

We have a blog written regarding setting up session replication in Payara Server, although the blog is written as part of a series using Apache web server, the setup should still be applicable when using AWS ECS.

The blog can be found here: Session Replication in Payara Server with Hazelcast

If you are still unable to configure session replication after following that blog, I will gladly take a further look.

Thanks,
James

I followed these steps.

I can see some action at the logs, but when I stop one of the two instances of the test the session is lost

|[#|2022-08-04T03:49:09.869+0000e[1;92m|INFO|e[0mPayara 5.2022.2|e[1;94mfish.payara.nucleus.cluster.PayaraCluster|e[0m_ThreadID=146;_ThreadName=hz.gracious_wu.event-7;_TimeMillis=1659584949869;_LevelValue=800;||
| --- | --- | --- | --- | --- | --- | --- |
|Data Grid Instance Added 69af623f-4e29-4c6f-b6e3-b342f6df6985 at Address /172.31.10.219:5701|#]|
|[#|2022-08-04T03:49:09.872+0000e[1;92m|INFO|e[0mPayara 5.2022.2|e[1;94mfish.payara.nucleus.cluster.PayaraCluster|e[0m_ThreadID=146;_ThreadName=hz.gracious_wu.event-7;_TimeMillis=1659584949872;_LevelValue=800;||
|Data Grid Status|
|Payara Data Grid State: DG Version: 4 DG Name: dev DG Size: 2|
|Instances: {|
|DataGrid: dev Name: server Lite: false This: true UUID: 74107202-7a29-4ae7-a840-b0f0b57f3b97 Address: /172.31.21.224:5701|
|DataGrid: dev Lite: false This: false UUID: 69af623f-4e29-4c6f-b6e3-b342f6df6985 Address: /172.31.10.219:5701|
|}|#]|

I was able to get this working by using hazelcast-wm, but I’m still interested in using payara’s embedded hazelcast.

Anyone?