WebSphere-Liberty 上用于 JCache 会话持久性的 Redisson:如何传递 redisson-jcache.yaml?

Redisson for JCache Session persistence on WebSphere-Liberty: how to pass redisson-jcache.yaml?

您好 Open Liberty 专家,

作为一项研发工作,我正在尝试启用由 Redis 通过 JCache/Redisson。我观察到 CLASSPATH 似乎是 通过 <library><httpSessionCache libraryRef> 语法正确配置, 但是配置文件没有被传递 至 org.redisson.jcache.JCacheManager.createCache()。此方法是 javax.cache.CacheManager.createCache()

的实现

这是我的server.xml:

<?xml version="1.0" encoding="UTF-8"?>
<server description="defaultServer">
    <!-- Enable features -->
    <featureManager>
        <feature>cdi-2.0</feature>
        <feature>jaxb-2.2</feature>
        <feature>jsf-2.3</feature>
        <feature>jaxrs-2.1</feature>
        <feature>ejbLite-3.2</feature>
        <feature>sessionCache-1.0</feature>        
    </featureManager>

    <!-- Define http & https endpoints -->
    <httpEndpoint id="defaultHttpEndpoint" host="*"
        httpPort="9080" httpsPort="9443" />

    <library id="jCacheVendorLib">
      <fileset dir="${shared.resource.dir}" includes="*"/>
      <folder dir="${shared.resource.dir}" />
    </library>

    <!-- trust JDK’s default truststore -->
    <ssl id="defaultSSLConfig"  trustDefaultCerts="true" />

    <httpSessionCache libraryRef="jCacheVendorLib"
                      uri="file:${shared.resource.dir}/redisson-jcache.yaml" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true" />

    <!-- Define web application with its context root and location -->
    <webApplication id="javaee-cafe" contextRoot="/"
        location="${server.config.dir}/apps/javaee-cafe.war">
    </webApplication>
</server>

不管我设置成什么值 uri="file:${shared.resource.dir}/redisson-jcache.yaml" 我还是明白了 Liberty 启动时出现此异常。

{
    "host": "javaee-app-simple-cluster-85b47b866c-h5mk4",
    "ibm_datetime": "2021-05-05T02:49:04.369+0000",
    "ibm_messageId": "SESN0307E",
    "ibm_sequence": "1620182944369_0000000000017",
    "ibm_serverName": "defaultServer",
    "ibm_threadId": "0000002a",
    "ibm_userDir": "/opt/ol/wlp/usr/",
    "loglevel": "ERROR",
    "message": "SESN0307E: An exception occurred when initializing the cache. The exception is: java.lang.IllegalStateException: Default configuration hasn't been specified!
  at org.redisson.jcache.JCacheManager.createCache(JCacheManager.java:118)
  at com.ibm.ws.session.store.cache.CacheHashMap.cacheInit(CacheHashMap.java:182)
  at com.ibm.ws.session.store.cache.CacheHashMap.lambda$new[=12=](CacheHashMap.java:134)
  at com.ibm.ws.session.store.cache.CacheHashMap$$Lambda/0000000000000000.run(Unknown Source)
  at java.security.AccessController.doPrivileged(AccessController.java:678)
  at com.ibm.ws.session.store.cache.CacheHashMap.<init>(CacheHashMap.java:133)
  at com.ibm.ws.session.store.cache.CacheStore.<init>(CacheStore.java:33)
  at com.ibm.ws.session.store.cache.CacheStoreService.createStore(CacheStoreService.java:316)
  at com.ibm.ws.session.SessionContext.createStore(SessionContext.java:337)
  at com.ibm.ws.session.SessionContext.createCoreSessionManager(SessionContext.java:254)
  at com.ibm.ws.session.SessionContext.<init>(SessionContext.java:157)
  at com.ibm.ws.webcontainer.session.impl.HttpSessionContextImpl.<init>(HttpSessionContextImpl.java:62)
  at com.ibm.ws.webcontainer31.session.impl.HttpSessionContext31Impl.<init>(HttpSessionContext31Impl.java:37)
  at com.ibm.ws.webcontainer31.session.impl.SessionContextRegistry31Impl.createSessionContextObject(SessionContextRegistry31Impl.java:40)
  at com.ibm.ws.webcontainer.session.impl.SessionContextRegistryImpl.createSessionContext(SessionContextRegistryImpl.java:83)
  at com.ibm.ws.webcontainer.session.impl.SessionContextRegistryImpl.getSessionContext(SessionContextRegistryImpl.java:304)
  at com.ibm.ws.webcontainer.WebContainer.getSessionContext(WebContainer.java:699)
  at com.ibm.ws.webcontainer.VirtualHost.getSessionContext(VirtualHost.java:188)
  at com.ibm.ws.webcontainer.webapp.WebGroup.getSessionContext(WebGroup.java:156)
  at com.ibm.ws.webcontainer.webapp.WebApp.createSessionContext(WebApp.java:1313)
  at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationStart(WebApp.java:1296)
  at com.ibm.ws.webcontainer.osgi.webapp.WebApp.commonInitializationStart(WebApp.java:254)
  at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1014)
  at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6683)
  at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:470)
  at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApplication(DynamicVirtualHost.java:465)
  at com.ibm.ws.webcontainer.osgi.WebContainer.startWebApplication(WebContainer.java:1178)
  at com.ibm.ws.webcontainer.osgi.WebContainer.access0(WebContainer.java:109)
  at com.ibm.ws.webcontainer.osgi.WebContainer.run(WebContainer.java:975)
  at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:239)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  at java.lang.Thread.run(Thread.java:823).",
    "module": "com.ibm.ws.session.store.cache.CacheHashMap",
    "type": "liberty_message"
}

我尝试为 uri="file:${shared.resource.dir}/redisson-jcache.yaml" 而且我还在 得到相同的结果:IllegalStateException 如上所示。我是什么 我不见了?

谢谢,

埃德

查看 Open Liberty 源代码,好像在获取 CacheManager 时将 uri 提供给 CachingProvider,

cacheManager = cachingProvider.getCacheManager(uri, null, vendorProperties);

查看代码在此处为 uri 提供的值将很有帮助,以确保它正确通过并且变量扩展正常工作且未损坏。为此,您可以打开以下跟踪:

<logging traceSpecification="*=info:com.ibm.ws.session.store.cache.*=all"/>

其中应该包括来自 JCache 方法的 entry/exit。

跟踪输出应出现在服务器输出文件夹下的 /logs/trace.log 中。

遗憾的是,这个问题的解决方案相当简单,解决问题则更为复杂。 redisson-jcache.yaml 文件中有错字。自从我认识 Ed 以来,我们一直在谈论堆栈溢出,我们发现 redisson-jcache.yaml 文件包含以下内容:

clusterServerConfig:
  password: ${clusterServerConfig.password}
  nodeAddresses:
  - ${clusterServerConfig.nodeAddresses}

原来应该是:

clusterServersConfig:
  password: ${clusterServerConfig.password}
  nodeAddresses:
  - ${clusterServerConfig.nodeAddresses}

注意正确的形式是将服务器作为复数。

所以出了什么问题,事实证明,如果 reddison yaml 文件由于任何原因没有解析,它会继续进行,就好像没有提供配置一样,没有错误消息来指示处理配置的问题是什么。然后它抛出一个神秘的异常,说没有提供配置。

将 printStackTrace 调用插入到 Redisson 代码库中的正确位置会产生一条有用的错误消息:

Unrecognized field "clusterServerConfig" (class org.redisson.config.Config), not marked as ignorable (23 known properties: "eventLoopGroup", "maxCleanUpDelay", "nettyHook", "keepPubSubOrder", "nettyThreads", "threads", "transportMode", "singleServerConfig", "sentinelServersConfig", "reliableTopicWatchdogTimeout", "useScriptCache", "minCleanUpDelay", "connectionListener", "executor", "codec", "replicatedServersConfig", "clusterServersConfig", "useThreadClassLoader", "masterSlaveServersConfig", "addressResolverGroupFactory", "lockWatchdogTimeout", "cleanUpKeysAmount", "referenceEnabled"])

所以这里的结论是绝对确定你的redisson yaml是正确的。修复后一切正常。