【发布时间】:2018-08-11 14:30:47
【问题描述】:
我设置了一个小项目来在集群环境中学习 Vert.x 的功能,但是当我尝试在 Docker 映像中创建 vertx 实例时遇到了一些奇怪的问题。
该项目仅包含 2 个部署在不同 Docker 容器中并使用事件总线相互通信的 Verticle
如果我使用 vertx 提供的启动器:
Launcher.executeCommand("run", verticleClass, "--cluster")
(或者只是说明主类是io.vertx.core.Launcher 并输入正确的参数)
一切都在本地和 docker 镜像中运行。但是如果我尝试手动创建 vertx 实例
Vertx.rxClusteredVertx(VertxOptions())
.flatMap { it.rxDeployVerticle(verticleClass) }
.subscribe()
然后它在 Docker 中不起作用(它在本地工作)。或者,更直观
| |本地 |码头工人 | |:---------------: |:-----: |:------: | | Vertx 启动器 |是 |是 | |自定义启动器 |是 | N |通过检查 Docker 日志,似乎一切正常。我可以看到两个verticles互相认识:
Members [2] {
Member [172.18.0.2]:5701 - c5e9636d-b3cd-4e24-a8ce-e881218bf3ce
Member [172.18.0.3]:5701 - a09ce83d-e0b3-48eb-aad7-fbd818c389bc this
}
但是当我尝试通过事件总线发送消息时,会抛出以下异常:
WARNING: Connecting to server localhost:33845 failed
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:33845
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:325)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:633)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused
... 11 more
只是为了简化我上传的项目to Github。我试图让它尽可能简单,所以它有 2 个 Verticle 和 2 个主类以及每个组合的大量脚本
【问题讨论】: