Caching Ehcache-jms复制websphereMQ

Caching Ehcache-jms复制websphereMQ,caching,replication,ibm-mq,ehcache,Caching,Replication,Ibm Mq,Ehcache,我正在尝试使用JMS WebsphereMQ v7作为提供程序来设置Ehcache复制。我使用ActiveMQ进行了复制,一切正常,但我正在尝试找出创建initialContext需要使用哪个类 这是当前使用ActiveMQ的代码,运行良好,我从中学习 ehcache.xml <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"

我正在尝试使用JMS WebsphereMQ v7作为提供程序来设置Ehcache复制。我使用ActiveMQ进行了复制,一切正常,但我正在尝试找出创建initialContext需要使用哪个类

这是当前使用ActiveMQ的代码,运行良好,我从中学习

ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" 
updateCheck="true"
monitoring="autodetect" 
dynamicConfig="true">
<diskStore path="java.io.tmpdir" />
<cacheManagerPeerProviderFactory
class="net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProviderFactory"
properties="initialContextFactoryName=ca.toyota.testcache.cache.ActiveMQContextFactory,
    providerURL=tcp://127.0.0.1:61616,
    replicationTopicConnectionFactoryBindingName=topicConnectionFactory,
    getQueueConnectionFactoryBindingName=queueConnectionFactory,
    getQueueBindingName=ehcacheGetQueue,
    listenToTopic=true,
    replicationTopicBindingName=ehcache"
propertySeparator="," />


<cache name="cacheTest1" 
    maxEntriesLocalHeap="10000"
    maxEntriesLocalDisk="1000" 
    eternal="false" 
    diskSpoolBufferSizeMB="20"
    timeToIdleSeconds="300" timeToLiveSeconds="600"
    memoryStoreEvictionPolicy="LFU" 
    transactionalMode="off">
    <persistence strategy="localTempSwap" />

    <cacheEventListenerFactory
    class="net.sf.ehcache.distribution.jms.JMSCacheReplicatorFactory"
 properties="replicateAsynchronously=true, 
                 replicatePuts=true,
                 replicateUpdates=true,
                 replicateUpdatesViaCopy=true,
              replicateRemovals=true,                                                
              asynchronousReplicationIntervalMillis=500"
    propertySeparator="," />
</cache>

ActiveMQContextFactory.java:

    package ca.toyota.testcache.cache;

import java.net.URISyntaxException;
import java.util.Hashtable;
import java.util.Map;

import javax.naming.Context;
import javax.naming.NamingException;

import org.apache.activemq.jndi.ActiveMQInitialContextFactory;

import net.sf.ehcache.distribution.jms.JMSUtil;
import net.sf.ehcache.util.concurrent.ConcurrentHashMap;

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);
    }

}
包ca.toyota.testcache.cache;
导入java.net.URISyntaxException;
导入java.util.Hashtable;
导入java.util.Map;
导入javax.naming.Context;
导入javax.naming.NamingException;
导入org.apache.activemq.jndi.ActiveMQInitialContextFactory;
导入net.sf.ehcache.distribution.jms.JMSUtil;
导入net.sf.ehcache.util.concurrent.ConcurrentHashMap;
公共类ActiveMQContextFactory扩展了ActiveMQInitialContextFactory{
@凌驾
公共上下文getInitialContext(哈希表环境)
抛出NamingException{
映射数据=新的ConcurrentHashMap();
//配置主题连接工厂绑定名称
String factoryBindingName=(字符串)环境
.get(JMSUtil.TOPIC_CONNECTION_FACTORY_BINDING_NAME);
试一试{
put(factoryBindingName,createConnectionFactory(环境));
}捕获(URISyntaxException e){
抛出新的NamingException(“初始化连接工厂时出错”
+“带消息”+e.getMessage());
}
String topicBindingName=(字符串)环境
.get(JMSUtil.REPLICATION\u TOPIC\u BINDING\u NAME);
put(topicBindingName,createTopic(topicBindingName));
//配置队列连接工厂绑定名称
String getQueueConnectionfactoryBindingName=(字符串)环境
.get(JMSUtil.get\队列\连接\工厂\绑定\名称);
if(getQueueConnectionfactoryBindingName!=null){
试一试{
data.put(getQueueConnectionfactoryBindingName,
createConnectionFactory(环境));
}捕获(URISyntaxException e){
抛出新的NamingException(
“初始化带有消息的TopicConnectionFactory时出错”
+e.getMessage());
}
}
String getQueueBindingName=(字符串)环境
.get(JMSUtil.get_队列_绑定_名称);
if(getQueueBindingName!=null){
put(getQueueBindingName,createQueue(getQueueBindingName));
}
返回createContext(环境、数据);
}
}
最后,我的问题是:我应该使用哪个InitialContextFactory来处理WebpshereMQ


感谢有同样问题的人,我几乎100%确定没有办法在WAS上使用JMS复制

使用WebsphereMQ设置ehcache复制后,我发现以下错误:

Caused by: net.sf.ehcache.CacheException: Exception while creating JMS connections: Method setExceptionListener not permitted
    at net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProvider.init(JMSCacheManagerPeerProvider.java:193)
    at net.sf.ehcache.CacheManager.doInit(CacheManager.java:479)
    at net.sf.ehcache.CacheManager.init(CacheManager.java:395)
    at net.sf.ehcache.CacheManager.<init>(CacheManager.java:270)
    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1116)
    at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1092)
    at net.sf.ehcache.CacheManager.create(CacheManager.java:1075)
    at org.springframework.cache.ehcache.EhCacheManagerFactoryBean.afterPropertiesSet(EhCacheManagerFactoryBean.java:139)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
    ... 127 more
Caused by: javax.jms.IllegalStateException: Method setExceptionListener not permitted
    at com.ibm.ejs.jms.JMSCMUtils.methodNotPermittedException(JMSCMUtils.java:244)
    at com.ibm.ejs.jms.JMSConnectionHandle.checkRestrictedMethod(JMSConnectionHandle.java:854)
    at com.ibm.ejs.jms.JMSConnectionHandle.setExceptionListener(JMSConnectionHandle.java:353)
    at net.sf.ehcache.distribution.jms.JMSCacheManagerPeerProvider.init(JMSCacheManagerPeerProvider.java:162)
    ... 136 more

此方法限制通过抛出javax.jms.IllegalStateException异常在WebSphere Application Server中强制实施。

EHCache jms规范兼容吗?我在thr JMS规范中没有看到任何“replicationTopic”,所以我猜没有。另外,您是想让MQ使用它还是曾经使用过它?因为问题的标签是IBMMQ,但答案是。
  javax.jms.Session method setMessageListener
  javax.jms.Session method getMessageListener
  javax.jms.Session method run
  javax.jms.QueueConnection method createConnectionConsumer
  javax.jms.TopicConnection method createConnectionConsumer
  javax.jms.TopicConnection method createDurableConnectionConsumer
  javax.jms.MessageConsumer method getMessageListener
  javax.jms.MessageConsumer method setMessageListener
  javax.jms.Connection setExceptionListener
  javax.jms.Connection stop
  javax.jms.Connection setClientID