我尝试使用JMS WebsphereMQ v7作为提供程序来设置Ehcache复制。我使用ActiveMQ进行了这种复制,并且everthing没问题,但是我试图弄清楚我需要使用哪个类来创建initialContext。
这是使用ActiveMQ的当前代码并且运行良好,我很高兴来自this post。
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);
}
}
最后我的问题是:我应该使用哪个InitialContextFactory来处理WebpshereMQ。
由于
答案 0 :(得分:0)
对于遇到同样问题的人,我几乎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
为了解决这个问题,我发现了以下常见问题:
ehCache复制指南说:
WebSphere Application Server阻止来自非MDB的MessageListeners
在容器中创建。
虽然这是一般的Java EE限制,但大多数其他应用服务器都是允许的
或者可以配置为许可。 WebSphere 4工作,但5和6强制执行
限制。
因此,Ehcache与JMS一起不能与WebSphere 5和6一起使用。
在Websphere 8文档(http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.0.0/com.ibm.websphere.nd.doc/info/ae/ae/tmj_desap.html?lang=it)上: 部分&#34; Java消息服务(JMS)要求&#34; J2EE规范提供了一个不能在Web和EJB容器中调用的方法列表:
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
通过抛出javax.jms.IllegalStateException异常,在WebSphere Application Server中强制实施此方法限制。