Vertx Eventbus无法在Java中运行 [英] Vertx Eventbus not working in Java

查看:44
本文介绍了Vertx Eventbus无法在Java中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OS LinuxJDK 1.7.0_67Vert.x 2.1.5

OS Linux JDK 1.7.0_67 Vert.x 2.1.5

刚刚开始连接github上的一些vertx示例.

Just getting started for wiring some of the vertx examples found on github.

由于该手册,我们希望通过EventBus尝试一个简单的Sender<-> Receiver示例.许多小时后,没有ping,也没有世界.

Due to the manual want to try out a simple Sender <-> Receiver example, over EventBus. Many hours later, no ping, neither a hello world.

任何人都有一个想法,这个简单的代码缺少我什么:

Anyone has an idea, what I'm missing on this simple code:

Sender.java

import org.vertx.java.platform.Verticle;

public class Sender extends Verticle {

  public void start(){
    vertx.eventBus().send("ping-address", "Hello");
  }
}

Receiver.java

import org.vertx.java.core.Handler;
import org.vertx.java.core.eventbus.EventBus;
import org.vertx.java.core.eventbus.Message;
import org.vertx.java.platform.Verticle;

public class Receiver extends Verticle {

  public void start() {
    EventBus eb = vertx.eventBus();
    eb.registerHandler("ping-address", new Handler<Message<String>>(){
        @Override
        public void handle(Message<String> message) {
            container.logger().info("Message: "+message.body());
        }
    });

    container.logger().info("PingVerticle started");

  }
}

使用以下CLI命令在同一台计算机上的单独JVM实例中同时运行这两个实例:

Running both in seperate JVM instances on the same machine, with following CLI command:

vertx run Receiver.java
> Succeeded in deploying verticle

另一个控制台:

vertx run Sender.java
> Succeeded in deploying verticle

推荐答案

在运行顶点时,它们将无法彼此看到.实际上,它们是作为完全独立的进程启动的,并且禁用了群集(默认设置).您必须以群集模式运行顶点,以使它们相互定位并进行通信.使用 -cluster 选项启用Hazelcast群集.您可能还需要指定 -host -port .

The way you're running the vertices, they won't be able to see each other. They're essentially being started as completely separate processes with clustering disabled (the default). You have to run the vertices in cluster mode in order to get them to locate and communicate with one another. Use the -cluster option to enable Hazelcast clustering. You may also want to specify -host or -port.

如果在此之后仍然继续出现总线通信问题,请启用Hazelcast日志记录,并确保两个节点能够互相看到.如果您的网络不支持多播,则可能必须更改 cluster.xml (Hazelcast配置).

If you continue seeing problems with even bus communication after that, enable Hazelcast logging and ensure the two nodes see each other. You may have to alter cluster.xml (the Hazelcast configuration) if your network does not support multicast.

这篇关于Vertx Eventbus无法在Java中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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