背景:
我们有 4 台物理服务器 (4 IPS),每台都在 JBOSS 6 EAP 中运行,在端口 80 上运行。所有请求都通过负载均衡器重定向到这些服务器中的任何一台。现在我尝试为这种分布式环境实现 Java 缓存系统,以便我们的属性在每个服务器缓存中得到更新。
POC: 为此,我们在实现 JCS v1.3 横向缓存的本地系统上做了一个小型 POC。在我们的 Maven 项目中启用它。.ccf 文件中使用了以下配置:
jcs.default=
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
# PRE-DEFINED CACHE REGION
##############################################################
##### AUXILIARY CACHES
# LTCP AUX CACHE
jcs.auxiliary.LTCP=org.apache.commons.jcs.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory
jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes
#jcs.auxiliary.LTCP.attributes.TcpServers=152.144.219.209:8080
jcs.auxiliary.LTCP.attributes.TcpListenerPort=1118
jcs.auxiliary.LTCP.attributes.UdpDiscoveryAddr=228.5.6.8
jcs.auxiliary.LTCP.attributes.UdpDiscoveryPort=6780
jcs.auxiliary.LTCP.attributes.UdpDiscoveryEnabled=true
jcs.auxiliary.LTCP.attributes.Receive=true
jcs.auxiliary.LTCP.attributes.AllowGet=true
jcs.auxiliary.LTCP.attributes.IssueRemoveOnPut=false
jcs.auxiliary.LTCP.attributes.FilterRemoveByHashCode=false
jcs.auxiliary.LTCP.attributes.SocketTimeoOt=1001
jcs.auxiliary.LTCP.attributes.OpenTimeOut=2002
jcs.auxiliary.LTCP.attributes.ZombieQueueMaxSize=2000
并实现 getter 和 setter 方法以将字符串属性保存在缓存中并从缓存中获取它
public void addProp(String propId)
throws PimsAppException {
try {
configMSCache.put(propId, propId);
} catch (CacheException e) {
e.printStackTrace();
}
}
@Override
public String testProp(String propId) throws PimsAppException {
if(configMSCache!=null){
return (String) configMSCache.get(propId);
}else{
return "It dint work";
}
}
该应用程序部署良好,启动时没有错误。
测试方法: 将 project.war 部署在我的本地服务器和具有不同 IP 的远程服务器中。两台机器都在同一个网络中,所以访问对方IP没有防火墙问题。在我的服务器中保存了一个属性并获取它。(工作正常)试图通过远程机器通过我的本地获取保存的属性。(它返回空白响应)。表示未实现分布式缓存功能。
疑问: 1. 辅助缓存是否设置正确?我的意思是配置 2. 我是否正确测试它或者如何在开发环境中测试它。3.作为JCS UDP Discovery,让我们在多台机器上支持相同的配置,那么为什么它在远程机器上工作?4. 或者是否有任何缓存机制,有很好的示例和文档可以满足我的应用程序需求(如背景部分所述)。
提前致谢。