同一主机上的 2 个实例之间的 ehcache 自动发现(通过多播)

发布于 2024-08-02 18:12:33 字数 1451 浏览 5 评论 0原文

我在同一主机上运行 2 个 tomcat 实例。每个实例都运行相同的 Web 应用程序,该应用程序尝试通过 RMI 复制与某些 ehcache 缓存进行通信。我在 ehcache 中使用自动发现配置,因此不必显式定义哪些是主机以及哪些是我想要复制的缓存。 ehcache 实例无法找到彼此并进行通信:

DEBUG (RMIBootstrapCacheLoader.java:211) - cache peers: []
DEBUG (RMIBootstrapCacheLoader.java:133) - Empty list of cache peers for cache org.hibernate.cache.UpdateTimestampsCache. No cache peer to bootstrap from.

如果我尝试同样的操作,但这次在单独的主机(盒子)上运行每个 tomcat 实例,那么一切都会像魅力一样工作。

我是否做错了什么,或者当实例位于同一主机上时,无法通过多播进行自动发现?

我的配置使用 RMI 分布式缓存文档中提供的默认值:

<cacheManagerPeerProviderFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, 
                    multicastGroupPort=4446, timeToLive=32"/>
<cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="port=40001, socketTimeoutMillis=2000"/>

并且在我想要的每个缓存区域内复制我有:

<cacheEventListenerFactory
        class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
        properties="asynchronousReplicationIntervalMillis=500 " />
<bootstrapCacheLoaderFactory 
        class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />

谢谢

I run 2 tomcat instances on the same host. Each instance runs the same web application which tries to communicate some ehcache caches via RMI replication. I use the autodiscovery configuration in ehcache so I don't have to explicitly define which are the hosts and which are the caches I want to replicate. The ehcache instances do not manage to find each other and communicate:

DEBUG (RMIBootstrapCacheLoader.java:211) - cache peers: []
DEBUG (RMIBootstrapCacheLoader.java:133) - Empty list of cache peers for cache org.hibernate.cache.UpdateTimestampsCache. No cache peer to bootstrap from.

If I try the same thing but this time run each tomcat instance on a separate host (box) then everything works like a charm.

Am I doing something wrong, or isn't autodiscovery via multicast possible when the instances are on the same host?

My configuration uses the defaults presented in the RMI Distributed Caching documentation:

<cacheManagerPeerProviderFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
        properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, 
                    multicastGroupPort=4446, timeToLive=32"/>
<cacheManagerPeerListenerFactory
        class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="port=40001, socketTimeoutMillis=2000"/>

And inside each cache region I want to replicate I have:

<cacheEventListenerFactory
        class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
        properties="asynchronousReplicationIntervalMillis=500 " />
<bootstrapCacheLoaderFactory 
        class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼藏柔 2024-08-09 18:12:33

我做错了什么吗?
可以通过多播进行自动发现
当实例处于同一位置时
主机?

虽然我不太熟悉 ehcache,但我认为这是可能的,而且他们实际上提供了一个示例,至少执行类似的操作(每个主机有多个节点,尽管只有一个实例):请参阅部分完整示例< /em> 在 RMI 分布式缓存 文档中提及。

通常,您不能在每个主机上多次打开同一个 TCP 端口(此处为 40001),但它绑定到分配它的第一个应用程序/服务(确实存在诸如 TCP 端口共享,但您必须专门考虑这一点)。

因此,如果您确实使用相同的默认配置,则尝试分配 TCP 端口 40001 的第二个 Tomcat 实例将失败。当然,这应该在 Tomcat 日志的较早位置体现出来,您已经彻底查看过了吗?

只需为一个 Tomcat 实例使用另一个空闲端口即可解决该问题;您可以在 ehcache 中看到此操作上面提到的完整示例的.xml:每个节点的端口号从 40001 逐一增加到 40006。

Am I doing something wrong, or isn't
autodiscovery via multicast possible
when the instances are on the same
host?

While I'm not really familiar with ehcache I'd think this to be possible and they are in fact providing an example doing something similar at least (multiple nodes per host, though one instance only): see section Full Example in the RMI Distributed Caching documentation you mentioned.

Usually you cannot open the same TCP port (40001 here) more than once per host though, it is bound to the first application/service allocating it (there do exist things like TCP Port Sharing on Windows for example, but you'd have to specifically account for that).

Consequently, if you are really using their identical default configurations, the second Tomcat instance trying to allocate TCP port 40001 will fail to do so. Of course, this should manifest itself somewhere earlier in the Tomcat logs, have you had a thorough look already?

Just using another free port for one Tomcat instance should solve the issue; you can see this in action within the ehcache.xml's for the Full Example mentioned above: the port number is increased one by one from 40001 up to 40006 per node.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文