Search code examples
jndiinfinispanwildfly-10

How to lookup Infinispan Cache in Non HA Wildfly 10


I have defined an Infinipan cache container with a cache (local-cache). In a cluster environment (high availability, e.g. standalone-full-ha.xml) there is no problem. Looking up for the cache reference with the @Resource Annotation works fine.

But when deploying into a Wildfly with a non clustered configuration (without HA, e.g. standalone-full.xml profile) this lookup fails with WFLYCTL0184: New missing/unsatisfied dependencies I still can define the caches with CLI scripts and I can see them in the runtime configuration. The difference is that the JNDI resource names are missing in the JNDI registry (this is why the lookup fails).

The problem is reproduceable with the Default standalone-full-ha.xml (which works) and the standalone-full.xml (with which the deployment fails).

How is it possible to lookup an Infinispan cache in a non clustered / non ha configuration? I would like to have the same code and deployment for caching whatever if a clustering profile is active or not.

CLI Script:

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

Lookup with @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-deployment-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>

Solution

  • An Infinispan cache-container that defines a transport has an implicit dependency on a JGroups channel. The standalone-full.xml profile does not define the requisite JGroups subsystem. Remove the 2nd line from your CLI script (the line that adds the transport) and you should be good to go.