如何配置Vert.x事件总线以跨Docker容器集群工作? [英] How do I configure Vert.x event bus to work across cluster of Docker containers?

查看:329
本文介绍了如何配置Vert.x事件总线以跨Docker容器集群工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当前设置中,我使用的是Hazelcast集群管理器的默认多播选项。当我链接容器化的Vertx模块的实例(通过Docker网络链接)时,可以看到它们成功创建了Hazelcast集群。但是,当我尝试从一个模块在事件总线上发布事件时,另一模块则没有反应。我不确定Hazelcast群集中的网络设置与事件总线的网络设置如何相关。

In my current setup, I'm using the default multicast option of the Hazelcast cluster manager. When I link the instances of my containerized Vertx modules (via Docker networking links), I can see that they are successfully creating Hazelcast cluster. However, when I try publishing events on the event bus from one module, the other module doesn't react to it. I'm not sure how the network settings in the Hazelcast cluster related to the network settings for the event bus.

目前,我对每个事件都有以下编程配置

At the moment, I have the following programmatic configuration for each of my Vert.x module, each deployed inside a docker container.

ClusterManager clusterManager = new HazelcastClusterManager();
VertxOptions vertxOptions = new VertxOptions()
            .setClustered(true)
            .setClusterManager(clusterManager);
vertxOptions.setEventBusOptions(new EventBusOptions()
            .setClustered(true)
            .setClusterPublicHost("application"));

Vert.x Core手册指出我可能必须配置 clusterPublicHost clusterPublicPort 用于事件总线,但我不确定它们与一般网络拓扑之间的关系。

The Vert.x Core manual states that I may have to configure clusterPublicHost, and clusterPublicPort for the event bus, but I'm not sure how those relate to the general network topology.

推荐答案

一个答案就在这里 https://groups.google.com/d/msg/vertx/_2MzDDowMBM/nFoI_k6GAgAJ


我知道这个问题很多,在
文档(包括我自己)中,很多人想念的是Event Bus不使用
集群管理器发送事件总线消息。即在以
Hazelcast作为群集管理器的示例中,您让Hazelcast群集建立了
并可以正常通信(因此您的Cluster Manager可以)。但是,由于以下一个或多个原因,事件总线
无法与您的其他docker
实例通信:

I see this question come up a lot, and what a lot of people miss in the documentation (myself included) is that Event Bus does not use the cluster manager to send event bus messages. I.e. in your example with Hazelcast as the cluster manager, you have the Hazelcast cluster up and communicating properly (so your Cluster Manager is fine); however, the Event bus is failing to communicate with your other docker instances due to one or more of the following:


  1. 它正在尝试对另一个节点使用错误的IP地址(即Docker实例上的私有接口的IP,而不是公共映射的
    的IP)

  2. 尝试在端口上进行通信Docker未配置为转发(如果未指定
    一个,事件总线会选择一个动态端口)

您需要做的是:


  1. 告诉Vertx其他节点用于与之通信的IP地址每个实例(使用-cluster-host [命令行],
    setClusterPublicHost [VertXOptions]或 vertx.cluster.public.host
    [系统属性]选项)

  2. 明确告诉Vertx端口用于事件总线通信,并确保Docker正在转发这些端口的流量(使用
    vertx.cluster .public.port [系统属性],setClusterPublicPort
    [VertXOptions]或-cluster-port [命令行]选项)。过去,
    我使用了15701,因为它很容易记住(在Hazelcast端口的
    中只有$ 1)。

事件总线仅使用群集管理器来管理其他Vertx实例的IP /端口
信息以及
消费者/生产者的注册。通信是独立于
集群管理器完成的,这就是为什么您可以正确配置集群管理器
并进行通信,但是仍然没有事件总线
通信的原因。

The Event bus only uses the Cluster Manager to manage the IP/Port information of the other Vertx Instances and the registration of the Consumers/Producers. The communications are done independently of the cluster manager, which is why you can have the cluster manager configured properly and communicating, but still have no Event bus communications.

如果两个容器
都在同一主机上运行,​​则可能不需要执行上述两个步骤,但是一旦启动
在单独的主机上运行它们,您肯定会执行

You may not need to do both the steps above if both your containers are running on the same host, but you definitely will once you start running them on separate hosts.

还有可能发生的事情是,当未指定vert.x的IP时,vert.x使用环回接口。而不是hazelcast)通过事件总线进行通信。这里的问题是,您不知道通过哪个接口进行通信(环回,与IP的接口,甚至可能有多个与IP的接口)。

Something what also can happen, is that vert.x uses the loopback interface, when not specifying the IP which vert.x (not hazelcast) should take to communicate over eventbus. The problem here is, that you don't know which interface is taken to communicate over (loopback, interface with IP, you could even have multiple interfaces with IP).

为了克服这个问题,我曾经> https://github.com/swisspush/vertx-cluster-watchdog/blob/master/src/main/java/org/swisspush/vertx/cluster/ClusterWatchdogRunner.java# L101

To overcome this problem, I wrote a method once https://github.com/swisspush/vertx-cluster-watchdog/blob/master/src/main/java/org/swisspush/vertx/cluster/ClusterWatchdogRunner.java#L101

这篇关于如何配置Vert.x事件总线以跨Docker容器集群工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆