-->

EhCache Replication with Websphere MQ

2020-07-27 02:04发布

问题:

Is it possible to use EHCache replication over JMS with IBM's Websphere MQ 7.0? I have a working sample using ActiveMQ (out of the box) but am not sure how to configure EHCache to work with Websphere MQ.

Below is a sample of my working ehcache.xml and ActiveMQInitialContextFactory configuration for ActiveMQ.

_______________________________ActiveMQ Sample_____________________________

ehcache.xml

<!-- ActiveMQ configuration out of the box -->
<cacheManagerPeerProviderFactory
    class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
    properties="initialContextFactoryName=com.hcsc.contextfactory.ActiveMQContextFactory,
        providerURL=tcp://LJGO4RAJ:61616,
        replicationTopicConnectionFactoryBindingName=topicConnectionFactory,
        getQueueConnectionFactoryBindingName=queueConnectionFactory,
        getQueueBindingName=ehcache,
        listenToTopic=true,
        replicationTopicBindingName=ehcache"
    propertySeparator="," />

<cache name="distributedCache" maxEntriesLocalHeap="1000"
    eternal="true" overflowToDisk="false">
    <cacheEventListenerFactory
        class="net.sf.ehcache.distribution.jms.JMSCacheReplicatorFactory"
     properties="replicateAsynchronously=true, 
                     replicatePuts=true,
                     replicateUpdates=true,
                     replicateUpdatesViaCopy=true,
                  replicateRemovals=true,                                                asynchronousReplicationIntervalMillis=500"
        propertySeparator="-" />

</cache>

ActiveMQInitialContextFactory implementation (from ehcache.xml)

public class ActiveMQContextFactory extends ActiveMQInitialContextFactory {

@Override
public Context getInitialContext(Hashtable environment)
        throws NamingException {

    Map<String, Object> data = new ConcurrentHashMap<String, Object>();

    // Configure the Topic connection factory binding name
    String factoryBindingName = (String) environment
            .get(JMSUtil.TOPIC_CONNECTION_FACTORY_BINDING_NAME);
    try {
        data.put(factoryBindingName, createConnectionFactory(environment));
    } catch (URISyntaxException e) {
        throw new NamingException("Error initialisating ConnectionFactory"
                + " with message " + e.getMessage());
    }

    String topicBindingName = (String) environment
            .get(JMSUtil.REPLICATION_TOPIC_BINDING_NAME);
    data.put(topicBindingName, createTopic(topicBindingName));

    // Configure queue connection factory binding name
    String getQueueConnectionfactoryBindingName = (String) environment
            .get(JMSUtil.GET_QUEUE_CONNECTION_FACTORY_BINDING_NAME);

    if (getQueueConnectionfactoryBindingName != null) {
        try {
            data.put(getQueueConnectionfactoryBindingName,
                    createConnectionFactory(environment));
        } catch (URISyntaxException e) {
            throw new NamingException(
                    "Error initialisating TopicConnectionFactory with message "
                            + e.getMessage());
        }
    }

    String getQueueBindingName = (String) environment
            .get(JMSUtil.GET_QUEUE_BINDING_NAME);
    if (getQueueBindingName != null) {
        data.put(getQueueBindingName, createQueue(getQueueBindingName));
    }

    return createContext(environment, data);
}

}

The above configuration works perfectly, but I need to convert it to use Websphere MQ. Below is what I have so far...

_______________________________WebsphereMQ Sample__________________________

ehcache.xml

<cacheManagerPeerProviderFactory
    class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
    properties="initialContextFactoryName=com.hcsc.contextfactory.WebSphereMQContextFactory,
        providerURL=tcp://LJGO4RAJ:1415,
        replicationTopicConnectionFactoryBindingName=topicConnectionFactory,
        getQueueConnectionFactoryBindingName=queueConnectionFactory,
        getQueueBindingName=myqueue,
        listenToTopic=true,
        replicationTopicBindingName=ehcache"
    propertySeparator="," />

<cache name="distributedCache" maxEntriesLocalHeap="1000"
    eternal="true" overflowToDisk="false">
    <cacheEventListenerFactory
        class="net.sf.ehcache.distribution.jms.JMSCacheReplicatorFactory"
        properties="replicateAsynchronously=true, 
                                            replicatePuts=true,
                                            replicateUpdates=true,
                                            replicateUpdatesViaCopy=true,
                                            replicateRemovals=true,
                                            asynchronousReplicationIntervalMillis=500"
        propertySeparator="-" />

</cache>

MQQueueConnectionFactory (I assume I need this similar to ActiveMQContextFactory)

public class WebSphereMQContextFactory extends MQQueueConnectionFactory {

// TODO - NOT SURE HOW TO CONFIGURE THIS FOR EHCACHE?

}

I believe I will need a MQQueueConnectionFactory similar to how I created one for ActiveMQ, am I going in the right direction? I cannot find any sample code to achieve this.