我試圖設置使用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工作。
感謝
是否符合EHCache JMS規範?我在thr JMS規範中沒有看到「replicationTopic」任何內容,所以我猜測沒有。另外,你是否試圖讓MQ使用這個或WAS?因爲問題被標記爲ibm-mq,但答案是關於WAS的。 –