2015-11-27 52 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的。 –