Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Externalize HTTP Session Data to the JBoss Data Grid

November 23, 2015
Guna Vijayaratnam
Related products:
Red Hat JBoss Enterprise Application Platform

Share:

    Introduction

    This article aims to provide a step by step guide for setting up a remote Red Hat JBoss Data Grid (JDG) cluster as an HTTP session store for your state-full web applications running on Red Hat JBoss Enterprise Application Platform (EAP). I had recently explored this setup for another customer and figured it would be helpful to put together a set of detailed instructions for replicating this. This feature was recently released with the GA of JDG 6.5.

    Benefits of this Solution

    Here are some of the reasons why you might want to consider this solution:

    1. Increased application scalability and elasticity. By offloading the session data off to a remote Data Grid, the application tier itself can be more scalable and elastic. Adding a new EAP instance to the cluster will not require a rehash process which could be problematic especially when we are dealing with a lot of session data.

       

    2. Session Persistence. By offloading session data to a remote data grid, the application itself will be able to survive EAP node failures since the a JVM failure will not cause the session data to be lost. In addition, additional cache persistence policies can be set up on the remote data grid so the session data is persisted to a user defined persistence medium.

       

    3. Session Data Sharing. If you have a requirement for multiple applications to be able to share session data, this solution might be able to solve that use case as well.

    Detailed Configuration

    Configuring JBoss EAP Cluster

    First we need to configure the Infinispan subsystem of the EAP server(s) to write session data to the remote JDG cluster. In order to do this, we will execute a set of EAP Command Line Interface (CLI) commands to configure the underlying cache container to preform this remote write of the Http Session data. All these commands can also be batched up and executed as a script they are going to be executed individually in this example.

    1. Create a new Cache Container which is going to be holding the definition for the session data cache.
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container:add(default-cache=remote-http-cache, module=org.jboss.as.clustering.web.infinispan)
    2. Create a remote cache inside the parent cache container. This is going to be referenced from the web application to externalize the session data.
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache:add(mode=ASYNC, batching=true)
      
    3. Add a new transport setting
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/transport=TRANSPORT:add(lock-timeout=60000)
      
    4. Define the remote Data Grid cluster to persist the session data
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:add(remote-servers=[{"outbound-socket-binding" => "remote-jdg-server1"}])
      
    5. Set the properties for the remote cache store:
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=cache, value=remote-http-cache)
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=socket-timeout, value=60000)
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=shared, value=true)
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=passivation, value=false)
      [standalone@localhost:9999 /] /subsystem=infinispan/cache-container=remote-http-container/distributed-cache=remote-http-cache/remote-store=REMOTE_STORE:write-attribute(name=purge, value=false)
      
    6. Define the Socket Binding profile with the actual address for the remote JDG servers
      [standalone@localhost:9999 /] /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-jdg-server1:add(host=localhost,port=11222)
      

    Configuring JBoss JDG Cluster

    1. Create a new cache store on the remote Data Grid Cluster to define the external cache that we are going to be persisting our session data to.
      [standalone@localhost:9999 cache-container=clustered] ./distributed-cache=remote-http-cache:add(mode=SYNC, start=EAGER)
      {"outcome" => "success"}
      
    2. You should also see the following confirmation on your JDG console
      INFO  [org.jboss.as.clustering.infinispan] (MSC service thread 1-7) JBAS010281: Started remote-http-cache cache from clustered container
      

    Now we are ready to test this solution!

    Verifying the Setup

    In order to verify this configuration, we first need a state full web application that is going persist data into the HttpSession object.

    You can access a sample stateful application from here.

      1. Deploy the above application into a JBoss EAP Cluster.
      2. You should notice that the application is not configured to write the session data to the remote JDG cluster. We need to make an update to the jboss-web.xml to define the cache-name for the session replication configuration.
        <?xml version="1.0" encoding="UTF-8"?>
        <jboss-web>
         <context-root>/counter</context-root>
         <replication-config>
              <replication-trigger>SET_AND_GET</replication-trigger>
              <replication-granularity>SESSION</replication-granularity>
              <cache-name>jboss.infinispan.remote-http-container.remote-http-cache</cache-name>
         </replication-config>
        
        </jboss-web>
        
      3. Access the application from one of the servers where it is deployed to. You should notice that the counter will increase.
      4. Now use the JDG cli to connect to the remote JDG server to verify that the session information has indeed been written to the data grid cluster.
        [standalone@localhost:9999 cache-container=clustered]  cd /subsystem=infinispan/cache-container=clustered/distributed-cache=remote-http-cache
        [standalone@localhost:9999 distributed-cache=remote-http-cache] stats
        Statistics: {
          removeHits: 0
          stores: 3
          numberOfEntries: 1
          hitRatio: 0.0
          removeMisses: 0
          averageRemoveTime: 0
          elapsedTime: 1060
          evictions: 0
          hits: 0
          misses: 8
          statisticsEnabled: true
          averageWriteTime: 0
          readWriteRatio: 2.6666666666666665
          averageReadTime: 0
          timeSinceReset: 1060
        }
        .
        .
        .
        

    The session data has been externalized successfully! You can also test the persistent aspect of this solution by shutting down the EAP server and then bring it back and access the application with the previous session id - this time EAP should be able to use the session id and query the cache for the session data and pick up from where it left off.

    Last updated: February 26, 2024

    Recent Posts

    • A case study in Kubelet regression in OpenShift

    • Profiling vLLM Inference Server with GPU acceleration on RHEL

    • Network performance in distributed training: Maximizing GPU utilization on OpenShift

    • Clang bytecode interpreter update

    • How Red Hat has redefined continuous performance testing

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue