繁体   English   中英

在 OpenLiberty 中使用 httpSessionCache 和 HazelCast 在不同应用程序之间共享会话数据

[英]Share sessions data between different apps using httpSessionCache and HazelCast in OpenLiberty

Usings the OpenLiberty sessionCache-1.0 feature with HazelCast enables you to easily persist and share session data in a HazelCast in-memory cluster as explained here: https://openliberty.io/guides/sessions.html .

However in this setup session data is stored internally in the maps named: com.ibm.ws.session.attr.[app-context-root] & com.ibm.ws.session.meta.[app-context-root] as 此处指出(尽管我没有看到 OpenLiberty 文档明确说明了这一点)

这可以防止不同的应用程序(具有不同的上下文根)共享 session 数据,因为它们正在从不同的命名映射写入和读取 session 数据。

有没有办法覆盖此名称以使具有不同上下文根的应用程序能够从同一 map 读取写入以共享 session 数据?

我正在查看 OpenLiberty 文档中的httpSession-httpSessionCache-properties ,但找不到任何支持此类内容的属性。

To share session between different Web apps within the same EAR, you can use shared-session-context in ibm-application-ext.xml to enable all Web apps use the same session context-root.

https://www.ibm.com/docs/en/was-liberty/base?topic=configuration-osgiapplication#application-ext

这是一个例子:

<?xml version="1.0" encoding="UTF-8"?>
<application-ext version="1.1" 
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-application-ext_1_1.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://websphere.ibm.com/xml/ns/javaee">
    
    <shared-session-context value="true"/>
</application-ext>

规范禁止在不同的应用程序之间共享 session 数据:

HttpSession 对象的范围必须在应用程序(或 servlet 上下文)级别。 [...] 引用的 object,包括 object 中的属性,决不能由容器在上下文之间共享。

所以如果你想在不同的应用程序之间共享一些数据,你必须创建单独的缓存,与会话无关。 您也可以使用 Hazelcast,而不是 session 缓存。

例如,如果所有应用程序都需要共享与给定用户相关的数据,则用户登录可能是缓存存储中的一个键。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM