简体   繁体   English

Vertx3 - EventBus无法在群集中运行

[英]Vertx3 - EventBus not working in a cluster

I am using vertx3. 我正在使用vertx3。 I tried with version 3.0.0 - 3.1.0 - 3.2.0-SNAPSHOT and in all of them is happening. 我试过版本3.0.0 - 3.1.0 - 3.2.0-SNAPSHOT,并且所有这些都在发生。

For simplify the problem I created 2 simple Verticles. 为了简化问题,我创建了2个简单的Verticle。 The first one act as a consumer of a message and the second one send a message through the event bus. 第一个充当消息的消费者,第二个通过事件总线发送消息。

The problem is that the eventBus looks not working and I am having timeouts when runs in a cluster. 问题是eventBus看起来不起作用,我在群集中运行时有超时。

I can't understand why as looks like that the second node joins the cluster, etc. 我无法理解为什么看起来第二个节点加入集群等等。

I add here the code. 我在这里添加代码。

public class FirstVerticle extends AbstractVerticle {
private final Logger log = LoggerFactory.getLogger(getClass());

@Override
public void start() {
    getVertx().eventBus().consumer("test-service", message -> {
        log.info(String.format("test-Service receive: %s", message));
        message.reply("ok");
    }).completionHandler(event -> {
        if(event.succeeded()) log.info("complete handler");
        else log.info("failed");
    });
    log.info("Done initializing");
}

} }

public class SecondVerticle extends AbstractVerticle {
private final Logger log = LoggerFactory.getLogger(getClass());

@Override
public void start() {
    log.info("Done initializing test");

    getVertx().setPeriodic(2000L, id -> {
        log.info("sending message test");
        getVertx().eventBus().send("test-service", "hi", response -> {
            if(response.succeeded()) log.info("success");
            else log.info("error?");
        });
    });
}

} }

I am running the verticles with 我正在运行Verticle

java -jar counter-service-1.0-SNAPSHOT-fat.jar -cluster -cluster-host 192.168.112.9

and the seecond one with: 和第二个:

java -jar test-service-1.0-SNAPSHOT-fat.jar -cluster -cluster-host 192.168.112.10

I have the following cluster.xml in the FirstVerticle 我在FirstVerticle中有以下cluster.xml

<network>
    <port auto-increment="true" port-count="10000">5701</port>
    <outbound-ports>
        <ports>0</ports>
    </outbound-ports>
    <join>
        <multicast enabled="false">
            <multicast-group>224.2.2.3</multicast-group>
            <multicast-port>54327</multicast-port>
        </multicast>
        <tcp-ip enabled="true" connection-timeout-seconds="10">
            <interface>192.168.112.9</interface>
            <interface>192.168.112.10</interface>
        </tcp-ip>
    </join>
    <interfaces enabled="true">
        <interface>192.168.112.*</interface>
    </interfaces>
</network>

and this cluster.xml in the SecondVerticle 和SecondVerticle中的这个cluster.xml

<network>
    <port auto-increment="true" port-count="10000">5701</port>
    <outbound-ports>
        <ports>0</ports>
    </outbound-ports>
    <join>
        <multicast enabled="false">
            <multicast-group>224.2.2.3</multicast-group>
            <multicast-port>54327</multicast-port>
        </multicast>
        <tcp-ip enabled="true" connection-timeout-seconds="10" >
            <interface>192.168.112.9</interface>
            <interface>192.168.112.10</interface>
        </tcp-ip>
    </join>
    <interfaces enabled="true">
        <interface>192.168.112.*</interface>
    </interfaces>
</network>

When I run the first verticle and after the second one I am having 当我运行第一个Verticle并且在第二个Verticle之后我正在运行

Members [2] {

Member [192.168.112.9]:5701 this

Member [192.168.112.10]:5701

}

and from the second node 并从第二个节点

Members [2] {

Member [192.168.112.9]:5701

Member [192.168.112.10]:5701 this

}

But I am only having from the second node 但我只是从第二个节点

sending message test 

and after 10 seconds 10秒后

Message reply handler timed out as no reply was received - it will be removed 

error? 

This is happening when is running in different machines, but when is running in the same machine everything is working fine. 当在不同的机器上运行时会发生这种情况,但是当在同一台机器上运行时,一切正常。 They are running in CentOS, firewall disabled, communication between internal IPs are fine.... so some idea ? 他们在CentOS中运行,防火墙禁用,内部IP之间的通信都很好....所以有些想法?

Thanks, 谢谢,

Finally I managed to make it works with different configurations, using tcp-ip and multicast. 最后,我设法使用tcp-ip和多播使其适用于不同的配置。

Basically the main problems is because of the blocking by the firewall or because multicast is not enabled. 基本上主要问题是由于防火墙阻塞或未启用多播。

Also one of the problems I had is when the server has more than one network interface, so has to be specify which one use in the cluster.xml 另外一个问题是当服务器有多个网络接口时,必须指定在cluster.xml中使用哪一个

I've created a github repository with 3 different configurations that finally are working fine in cluster hope it helps. 我已经创建了一个具有3种不同配置的github存储库,最终在集群中正常运行,希望它有所帮助。

https://github.com/mustaine/vertx3-ping-pong https://github.com/mustaine/vertx3-ping-pong

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM