[英]EhCache replication fully described in Java class doesn't work
我正在嘗試同步2個WAR-s- A.war和B.war的緩存 。 它們部署在一個Tomcat上。 每個WAR都包含具有init -method的下一個bean:
@Autowired
public class CacheService {
enum Cache {CACHE_1, CACHE_2};
@Autowired
private String cachePort;
public void init() throws Exception {
Configuration config = new Configuration();
FactoryConfiguration providerConfig = new FactoryConfiguration();
providerConfig.setClass("net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory");
providerConfig.setPropertySeparator(",");
providerConfig.setProperties("peerDiscovery=automatic,multicastGroupAddress=230.0.0.1,multicastGroupPort=4446");
config.addCacheManagerPeerProviderFactory(providerConfig);
FactoryConfiguration listenerConfig = new FactoryConfiguration();
listenerConfig.setClass("net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory");
listenerConfig.setPropertySeparator(",");
listenerConfig.setProperties("hostName=localhost,port=" + cachePort);
config.addCacheManagerPeerListenerFactory(listenerConfig);
CacheConfiguration defaultConfig = new CacheConfiguration();
defaultConfig.setTimeToLiveSeconds(120);
defaultConfig.setDiskExpiryThreadIntervalSeconds(120);
defaultConfig.setMemoryStoreEvictionPolicy("LRU");
defaultConfig.setStatistics(true);
defaultConfig.setMaxBytesLocalHeap(MemoryUnit.MEGABYTES.toBytes(1));
config.setDefaultCacheConfiguration(defaultConfig);
cacheManager = new CacheManager(config);
for (Cache cache : Cache.values()) {
cacheManager.addCache(cache.name());
net.sf.ehcache.Cache createdCache = cacheManager.getCache(cache.name());
createdCache.getCacheConfiguration().setTimeToLiveSeconds(600);
createdCache.getCacheEventNotificationService().registerListener(new RMIAsynchronousCacheReplicator(true, true, true, true, true, 5000, 1000));
}
}
}
A.war : cachePort = 40001
B.war : cachePort = 40002
但是緩存不同步。 可能是RMICacheManagerPeerProviderFactory,RMICacheManagerPeerListenerFactory或RMIAsynchronousCacheReplicator中某處的參數錯誤。
有人可以幫忙嗎?
而且,如果可能的話,有人能描述將這2個WAR部署在1個子網中2台計算機上的不同雄貓上的情況嗎?
先感謝您。
我猜測:
hostname=localhost
您可以通過檢查聽音來驗證它(打開net.sf.ehcache.distribution log4j
)。 主機名應為真實IP地址,而不是127.0.0.1
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.