如何在非 HA Wildfly 10 中查找 Infinispan 缓存

How to lookup Infinispan Cache in Non HA Wildfly 10

我已经定义了一个带有缓存(local-cache)的Infinipan缓存容器。 在集群环境下(高可用,例如standalone-full-ha.xml)是没有问题的。 使用 @Resource 注释查找缓存引用工作正常。

但是当部署到具有非集群配置(没有 HA,例如独立-full.xml 配置文件)的 Wildfly 时,此查找失败并显示 WFLYCTL0184:新 missing/unsatisfied 依赖项 我仍然可以使用 CLI 脚本定义缓存,并且可以在运行时配置中看到它们。 不同之处在于 JNDI 注册表中缺少 JNDI 资源名称(这就是查找失败的原因)。

使用默认的独立完整-ha.xml(有效)和独立-full.xml(部署失败)可以重现该问题。

如何在非集群/非 ha 配置中查找 Infinispan 缓存? 无论集群配置文件是否处于活动状态,我都希望使用相同的代码和部署来缓存。

CLI 脚本:

batch
/subsystem=infinispan/cache-container=test-cache-container/:add(default-cache=test-cache,jndi-name=java:jboss/infinispan/container/test)
/subsystem=infinispan/cache-container=test-cache-container/transport=TRANSPORT/:add(lock-timeout=30000)
/subsystem=infinispan/cache-container=test-cache-container/local-cache=test-cache:add(indexing=NONE,jndi-name=infinispan/test-cache-container/test-cache)
/subsystem=infinispan/cache-container=test-cache-container/local-cache=test-cache/transaction=TRANSACTION:add(locking=PESSIMISTIC, mode=FULL_XA)
/subsystem=infinispan/cache-container=test-cache-container/local-cache=test-cache/eviction=EVICTION:add(strategy=NONE)
/subsystem=infinispan/cache-container=test-cache-container/local-cache=test-cache/locking=LOCKING:add(acquire-timeout=30000,isolation=REPEATABLE_READ)
run-batch

使用@Resource 查找:

@Singleton
@Remote(DataStore.class)
public class DataStoreBean implements DataStore {

    @Resource(lookup = "java:jboss/infinispan/test-cache-container/test-cache")
    private Cache<String, Object> cache;

jboss-部署-structure.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
    <deployment>
        <dependencies>
            <module name="org.infinispan" export="true"/>
            <module name="org.infinispan.commons" export="true"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>

定义传输的 Infinispan 缓存容器对 JGroups 通道具有隐式依赖性。 standalone-full.xml 配置文件没有定义必需的 JGroups 子系统。从您的 CLI 脚本中删除第二行(添加传输的行),您应该可以开始了。