2015-11-27 53 views
0

我试图设置使用JMS WebsphereMQ v7作为提供程序的Ehcache复制。我使用ActiveMQ做了这种复制,并且everthing是可以的,但我试图找出我需要使用哪个类来创建initialContext。Ehcache jms复制websphereMQ

这是使用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

对于有同样的问题的人,我几乎可以100%肯定是没有办法使用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): J2EE规范的章节 “Java消息服务(JMS)要求” 给出了一个列表那一定不要在Web和EJB容器调用的方法:通过投掷javax.jms.IllegalStateExcept

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 

这种方法限制在WebSphere Application Server强制执行离子例外。

+0

是否符合EHCache JMS规范?我在thr JMS规范中没有看到“replicationTopic”任何内容,所以我猜测没有。另外,你是否试图让MQ使用这个或WAS?因为问题被标记为ibm-mq,但答案是关于WAS的。 –