简体   繁体   English

Redisson for JCache Session 在 WebSphere-Liberty 上的持久性:如何通过 redisson-jcache.yaml?

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

Hello Open Liberty experts,您好 Open Liberty 专家,

As an R&D effort, I am trying to enable Liberty session persistence backed by Redis via JCache/Redisson.作为一项研发工作,我正在尝试通过 JCache/Redisson 启用由 Redis 支持的 Liberty session 持久性。 I observe the CLASSPATH seems to be correctly configured via <library> and <httpSessionCache libraryRef> syntax, but the config file is not being passed to org.redisson.jcache.JCacheManager.createCache() .我观察到 CLASSPATH 似乎通过<library><httpSessionCache libraryRef>语法正确配置,但配置文件没有被传递给org.redisson.jcache.JCacheManager.createCache() This method is an implementation of javax.cache.CacheManager.createCache()该方法是javax.cache.CacheManager.createCache()的一个实现

Here is my server.xml :这是我的服务器。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>

Regardless of what value I set as uri="file:${shared.resource.dir}/redisson-jcache.yaml" I still get this exception at startup time for Liberty.无论我将什么值设置为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$0(CacheHashMap.java:134)
  at com.ibm.ws.session.store.cache.CacheHashMap$$Lambda$90/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.access$100(WebContainer.java:109)
  at com.ibm.ws.webcontainer.osgi.WebContainer$3.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"
}

I tried setting a completely bogus value for uri="file:${shared.resource.dir}/redisson-jcache.yaml" and I still get the same result: IllegalStateException as shown above.我尝试为uri="file:${shared.resource.dir}/redisson-jcache.yaml"设置一个完全虚假的值,但我仍然得到相同的结果:如上所示的IllegalStateException What am I missing?我错过了什么?

Thanks,谢谢,

Ed埃德

Looking at Open Liberty source code, it looks like the uri is supplied to the CachingProvider when obtaining a CacheManager,查看 Open Liberty 源代码,看起来 uri 在获取 CacheManager 时提供给 CachingProvider,

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

It will be helpful to see the value that code is supplying here for the uri to ensure that it is getting through correctly and that the variable expansion is working and it isn't corrupted.查看代码在此处为 uri 提供的值将很有帮助,以确保它正确通过并且变量扩展正在工作并且没有损坏。 To do that, you could turn on the following trace:为此,您可以打开以下跟踪:

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

which ought to include, among other things, entry/exit from JCache methods.其中应该包括 JCache 方法的进入/退出等。

The trace output should appear in /logs/trace.log under your server output folder.跟踪 output 应出现在您的服务器 output 文件夹下的 /logs/trace.log 中。

Sadly solution to this problem is fairly simple, working out the problem was more complicated.可悲的是,这个问题的解决方案相当简单,解决这个问题更加复杂。 There was a typo in the redisson-jcache.yaml file. redisson-jcache.yaml 文件中有错字。 Since I know Ed we have been talking off stack overflow and we discovered the redisson-jcache.yaml file contained this:因为我知道 Ed 我们一直在谈论堆栈溢出,我们发现 redisson-jcache.yaml 文件包含以下内容:

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

it turns out that it should have been:事实证明它应该是:

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

note the correct form has server as plural.注意正确的形式有 server 作为复数形式。

So what went wrong, it turns out that if the reddison yaml file doesn't parse for any reason it proceeds as if no configuration was provided with no error message to indicate what the problem processing the configuration was.那么出了什么问题,事实证明,如果 reddison yaml 文件由于任何原因没有解析,它就会继续进行,就好像没有提供配置一样,没有错误消息表明处理配置的问题是什么。 It then throws a cryptic exception saying no configuration was provided.然后它抛出一个神秘的异常,说没有提供配置。

Inserting a printStackTrace call into the right place in the Redisson code base resulted in a useful error message that said:将 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"])

So the conclusion here is to make absolutely sure your redisson yaml is correct.所以这里的结论是绝对确保你的 redisson yaml 是正确的。 Having fixed that everything worked.修复后一切正常。

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

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