Skip to content

📝 Example of externalizing HTTP sessions from EAP into a clustered Data Grid - on OpenShift

License

Notifications You must be signed in to change notification settings

dudash/eap-external-http-sessions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenShift Version

EAP External HTTP sessions

Example of externalizing HTTP sessions from JBoss EAP (aka Wildfly) into a clustered Data Grid - on OpenShift

Why sessions?

Basically, because you need a place to store data specific to a user using your webapp. It's likely you either know or have heard folks says "HTTP is stateless". But users interacting with your webapp expect an experience where the app remembers things about them and what they're doing (a typical example of this is a shopping cart). Stateless HTTP and keeping info about the user are opposing things. And so sessions are used a way to keep user state.

Why external?

This allows scaling of the sessions independent of the application. And by having the data layer reside external to JBoss EAP, different JBoss EAP instances can access shared data. So this independence is a nice architectural design that protects your session data in the case of server containers crashing or recreating/patching an application server. It also has the advantage of keeping individual JBoss EAP instances lighter and free of heap usage.

What is Data Grid?

Data Grid is really what we are showcasing here. It's an extremely scalable, highly available key/value data store. We are using it in this case to externalize the EAP user sessions. It is often used as a distributed cache, but also can serve as a NoSQL key/value store or object database. It can be used in several different ways to accelerate development and to improve performance of both legacy and modern applications. You can learn more about Data Grid here.

Setup & demo steps

You will need an OpenShift cluster to run this demo. If you don't have a cluster, try using the CDK for 3.x versions of OpenShift. And soon CodeReady Containers will be available for 4.x versions of OpenShift.

Everything will reside in the same project. So let's create that first: oc new-project eap-dg-demo

1 - Install data grid

Run the following commands to setup Data Grid (uses templates, in the future there will be an Operator to do the install)

oc new-app --template=datagrid73-basic \
  -p CACHE_NAMES=default,testing \
  -p APPLICATION_NAME=cache-service

oc scale --replicas=3 dc cache-service

ℹ️ Data Grid is part of the OpenShift Runtimes bundle. If you own Runtimes but don't see Data Grid templates in your OpenShift cluster you need to follow steps here (additional service templates steps here).

2 - Build & deploy the app in EAP on OpenShift

Run the following command to create a bunch of OpenShift resources that will clone, build the code, build a container, deploy, and run our webapp:

oc new-app --template=eap71-basic-s2i \
  -p SOURCE_REPOSITORY_URL=https://github.com/dudash/eap-external-http-sessions \
  -p SOURCE_REPOSITORY_REF=master \
  -p CONTEXT_DIR= \
  -e JGROUPS_PING_PROTOCOL=openshift.DNS_PING \
  -e OPENSHIFT_DNS_PING_SERVICE_NAME=eap-app-ping \
  -e OPENSHIFT_DNS_PING_SERVICE_PORT=8888 \
  -e CACHE_NAME=default

Now scale the webapp to 2 replicas: oc scale --replicas=2 dc eap-app

3 - Demo steps

If everything above worked without errors, you are good to test a few things out.

Let's check we can put/get data into the cache. Put something in with:

curl -X PUT -u developer:password \
  -H 'Content-type: text/plain' \
  -d 'world' \
  http://{YOUR-CACHE-ROUTE}/rest/testing/hello

Pull that back out with:

curl -i -u developer:password \
  -H 'Content-type: text/plain' \
  http://{YOUR-CACHE-ROUTE}/rest/testing/hello

...

Now, let's check the JMX console and make sure EAP is clustered and using Data Grid:

In the OpenShift console, click Applications->Pods, and choose one of the Data Grid pods (it'll look like cache-service-1-hz8fp). On the right side in the Containers section you should have a link for "Open Java Console". Click to open that up.

If you expand the clustering details you should see a cluster size of 3 just like the screenshot below: clustered

And let's access the webapp and see that our session data is being maintained.

In the OpenShift console, find the route for your webapp and click it. Add /http-session-counter/ to the end of it. Now refresh the page a few times. You'll see the counter incrementing for this session and it will sometimes be served by different EAP container instances. Woot woot! the session is external.

It'll look like this: webapp

Now if you want to try deleting pods or killing containers and seeing how the user session stays around, go for it.

4 (Coming Soon) Extra credit - use with CodeReady Workspaces

Let's use a web IDE called CodeReady Workspaces to change the app's code, build a new container, and deploy it.

CLICK HERE TO GET THE EXTRA CREDIT STEPS

About the code / software architecture

The parts in action here are:

  • Demo JSP webapp (thanks to mvocale because I based this off his example)
  • Middleware components for:
  • OpenShift/Kubernetes for:
    • Operator to deploy/manage Data Grid
    • Automatic IP address/ports via SDN
    • Load balancing, deployment replication for scaled EAP servers
    • Load balancing, stateful mgmt for scaled Data Grid cluster
    • Router for getting HTTP traffic to our load balanced application

Now What? Next Steps

Get deeper and try other examples of using Data Grid, click the link for this repo with for more content:

About

📝 Example of externalizing HTTP sessions from EAP into a clustered Data Grid - on OpenShift

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages