同一主机上的 JGroups 成员集群仅使用一个地址

JGroups cluster of members on the same host is using only one address

我想使用 JGroups 开发一些分布式应用程序。但不幸的是,我无法在集群中获得超过一个成员。他们总是加入同一个地址:

    this.channel = new JChannel("udp.xml");
    channel.connect("test-cluster");
    this.rpcDispatcher = new RpcDispatcher(channel, null, null, this);
    this.myAddress = channel.getAddress();

    System.out.println("joined cluster: " + channel.getView().size() + ", " + channel.getView());

当我开始两个(或更多)调试会话时,我总是会以大小为 1 的集群结束。

joined cluster: 1, [Jimbo-3806|0] [Jimbo-3806]

因此,您无法将直接消息从一个 jvm 发送到另一个(因为您需要传递相同的地址)。

我正在使用与 JGroups 捆绑的默认 udp.xml。

以防其他人遇到这个问题。确保 draw demo 正常工作并且您的 JVM 使用 IPv4(这很重要)。在我的例子中,JVM 坚持使用 IPv6,我不得不强制 JVM 像这样使用 IPv4:

System.setProperty("java.net.preferIPv4Stack", "true");
Channel channel = new JChannel("udp.xml");
channel.connect("test-cluster");