Vertx Eventbus 发送节点间失败
Vertx Eventbus failed to send inter-nodes
我有一个小演示演示了 Vertx 如何使用 Hazelcast 集群管理器通过 Eventbus 在节点之间发送消息。
至此,我已经成功让节点相互识别了。
Members [2] {
Member [192.168.150.193]:5701 - 0c8120d8-73dc-4fc2-af6d-16288dbd707a
Member [192.168.130.41]:5701 - 19239bb1-e7e8-4990-a389-817d6a7d128a this
}
但是后来,我遇到了Cluster成员之间EventBus通信的问题。根据 Vertx 手册页。
Cluster managers do not handle the event bus inter-node transport, this is done directly by Vert.x with TCP connections.
但是,即使我事先通过以下方式从集群管理器获得集群事件总线:
public static EventBus clusterEB = null;
...
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
clusterEB = vertx.eventBus();
vertx.deployVerticle(new DemoVerticle());
}
});
当 local 节点的主 Verticle 使用该静态 eventbus 对象向 remote 节点发送消息时。
eb.send("worker.count", request_count, res -> {
if (res.succeeded()) {
System.out.println("Received reply No." + res.result().body());
worker_busy--;
System.out.println("WORKER_BUSY = " + worker_busy);
}
});
抛出异常:
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:50509
通过netstat,我发现50509是远程节点eventbus正在监听的端口。因此,我猜测我的配置遗漏了一些导致 Vertx 弄错地址的东西,如果我错了请纠正我。
这些信息是我目前研究的信息,我真的很期待听到你们对这个问题的任何建议。如果您需要更多信息,请随时问我。
p/s: 本地节点间的Event Bus通信还是可以的。 Ubuntu 上的代码 运行(禁用 UFW),远程机器是 Windows,防火墙关闭(我认为防火墙在这里不是问题,因为要列出的节点之间仍然存在 tcp 连接网络中的所有集群成员)
看起来 vert.x 为您的主机 (127.0.0.1) 选择了错误的 IP 地址,而实际上它们是:
- 192.168.150.193
- 192.168.130.41
您可能希望通过添加以下额外的命令行参数来强制每个节点 select 正确的 IP 地址:
-cluster-host 192.168.150.193
另一个节点也一样:
-cluster-host 192.168.130.41
遇到同样问题的朋友,希望我的回答对您有所帮助。
感谢@Paulo_Lopes的建议,稍加调整就解决了我的问题
我必须以编程方式设置集群主机,例如:
VertxOptions options = new VertxOptions().setClusterManager(mgr).setClusterHost("192.168.130.21");
Vertx Hazelcast 的文档也有关于此的简要信息:
When running Vert.x is in clustered mode, you should also make sure
that Vert.x knows about the correct interface. When running at the
command line this is done by specifying the cluster-host option...
不过老实说,我觉得他们应该用更容易理解的方式。简而言之,您必须将您的机器 IP 指定为集群主机,因为集群事件总线将采用该 IP 并为节点间通信注册一个套接字。如果没有设置集群主机配置,Vertx 将以您的 'localhost' (127.0.0.1) 作为 IP,通过 Vertx 发送的每条消息将只能到达本地节点。
就是这样。希望它能帮助有需要的人,非常感谢你,@Paulo。
我有一个小演示演示了 Vertx 如何使用 Hazelcast 集群管理器通过 Eventbus 在节点之间发送消息。
至此,我已经成功让节点相互识别了。
Members [2] {
Member [192.168.150.193]:5701 - 0c8120d8-73dc-4fc2-af6d-16288dbd707a
Member [192.168.130.41]:5701 - 19239bb1-e7e8-4990-a389-817d6a7d128a this
}
但是后来,我遇到了Cluster成员之间EventBus通信的问题。根据 Vertx 手册页。
Cluster managers do not handle the event bus inter-node transport, this is done directly by Vert.x with TCP connections.
但是,即使我事先通过以下方式从集群管理器获得集群事件总线:
public static EventBus clusterEB = null;
...
Vertx.clusteredVertx(options, res -> {
if (res.succeeded()) {
Vertx vertx = res.result();
clusterEB = vertx.eventBus();
vertx.deployVerticle(new DemoVerticle());
}
});
当 local 节点的主 Verticle 使用该静态 eventbus 对象向 remote 节点发送消息时。
eb.send("worker.count", request_count, res -> {
if (res.succeeded()) {
System.out.println("Received reply No." + res.result().body());
worker_busy--;
System.out.println("WORKER_BUSY = " + worker_busy);
}
});
抛出异常:
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:50509
通过netstat,我发现50509是远程节点eventbus正在监听的端口。因此,我猜测我的配置遗漏了一些导致 Vertx 弄错地址的东西,如果我错了请纠正我。
这些信息是我目前研究的信息,我真的很期待听到你们对这个问题的任何建议。如果您需要更多信息,请随时问我。
p/s: 本地节点间的Event Bus通信还是可以的。 Ubuntu 上的代码 运行(禁用 UFW),远程机器是 Windows,防火墙关闭(我认为防火墙在这里不是问题,因为要列出的节点之间仍然存在 tcp 连接网络中的所有集群成员)
看起来 vert.x 为您的主机 (127.0.0.1) 选择了错误的 IP 地址,而实际上它们是:
- 192.168.150.193
- 192.168.130.41
您可能希望通过添加以下额外的命令行参数来强制每个节点 select 正确的 IP 地址:
-cluster-host 192.168.150.193
另一个节点也一样:
-cluster-host 192.168.130.41
遇到同样问题的朋友,希望我的回答对您有所帮助。
感谢@Paulo_Lopes的建议,稍加调整就解决了我的问题
我必须以编程方式设置集群主机,例如:
VertxOptions options = new VertxOptions().setClusterManager(mgr).setClusterHost("192.168.130.21");
Vertx Hazelcast 的文档也有关于此的简要信息:
When running Vert.x is in clustered mode, you should also make sure that Vert.x knows about the correct interface. When running at the command line this is done by specifying the cluster-host option...
不过老实说,我觉得他们应该用更容易理解的方式。简而言之,您必须将您的机器 IP 指定为集群主机,因为集群事件总线将采用该 IP 并为节点间通信注册一个套接字。如果没有设置集群主机配置,Vertx 将以您的 'localhost' (127.0.0.1) 作为 IP,通过 Vertx 发送的每条消息将只能到达本地节点。
就是这样。希望它能帮助有需要的人,非常感谢你,@Paulo。