Wildfly session replication external/dedicated Infinispan

245 views
Skip to first unread message

Álvaro Nogueira

unread,
Aug 1, 2022, 5:56:32 AM8/1/22
to WildFly
Hi, I managed to setup my web application to use a external infinispan to replicate the user session among the wildfly nodes. Knowing that the infinispan stores data in key/value, what is used as key to stores the session? 

PS:
I have another application with spring-boot that utilizes infinispan to replicate the session, in this case the sessionId (cookie) is used as key, but with wildfly It seems not to be the case.

Paul Ferraro

unread,
Aug 1, 2022, 9:14:17 AM8/1/22
to WildFly
WildFly stores data for a given HttpSession within multiple cache entries:

1. One cache entry stores session meta data that is static or changes infrequently. (i.e. creation time, max-inactive-interval).
2. One cache entry stores session meta data that changes frequently (i.e. last access time)
3. One of more cache entries store session attributes, depending on the configured granularity:
  a. SESSION granularity stores all session attribute in a single cache entry as a map of name->value
  b. ATTRIBUTE granularity stores each session attribute in a separate cache entry, and uses a separate cache entry per session containing a map of session attribute names.

Consequently, WildFly uses a custom key class for each of the above cache keys, e.g.

Specifically, session identifiers in WildFly are marshalled via:

You may be interested to know that WildFly's distributed session manager implementation is available for use with Spring Session, for use with any application server (not just WildFly):

Álvaro Nogueira

unread,
Aug 2, 2022, 11:32:42 AM8/2/22
to WildFly
Hi, thanks for the reply

I'm trying to mannualy load the session atribute in another application (not in wildfly server) with a hotrod client, since the infinispan utilizes the PROTOSTREAM to marshal the data
I believe that I need to provide a custom marshall to the SerializationContext, so I'm trying replicate the same steps that is implemented in wildfly, and also imported the wildfly-clustering-web-hotrod to reuse the classes:

//Load the cache:
RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
RemoteCache<Object, Object> remoteCache = cacheManager.getCache("mycache");

//Setup the serializationContext
SerializationContext ctx = MarshallerUtil.getSerializationContext(cacheManager);
FileDescriptorSource fds = FileDescriptorSource.fromResources(this.getClass().getClassLoader(), "sessionkey.proto");       // same as org.wildfly.clustering.web.hotrod.session.coarse
ctx.registerMarshaller(new SessionKeyMarshaller<>(SessionAttributesKey.class, SessionAttributesKey::new, IdentifierMarshaller.BASE64));    // I also tried with the ISO and HEX
ctx.registerProtoFiles(fds);

// Trying to load the cache given a sessionID
SessionAttributesKey s = new SessionAttributesKey("bHuPNzQexya5QRi33EU7gk2fw_gwXtSDBufNEk86");
remoteCache.get(s);

The last step is returning null.

This is the right approach or am I missing something?

Paul Ferraro

unread,
Aug 2, 2022, 2:06:07 PM8/2/22
to WildFly
WildFly uses its own Marshaller implementation (which is distinct from Infinispan's default ProtoStream marshaller). See:
Reply all
Reply to author
Forward
0 new messages