[英]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.