Reputation: 899
We were trying to establish communication between verticles using event bus. We tried the simplest ping-pong communication example -
public class Sender extends AbstractVerticle {
public static void main(String[] args) {
Vertx.clusteredVertx(new VertxOptions(),res->{
res.result().deployVerticle(new Sender());
});
}
@Override
public void start() throws Exception {
EventBus eb = vertx.eventBus();
vertx.setPeriodic(1000, v -> {
eb.send("ping-address", "ping!", reply -> {
if (reply.succeeded()) {
System.out.println("Received reply: " + reply.result().body());
} else {
System.out.println("No reply");
}
});
});
}
}
Similarly we wrote the wrote the receiver. See the code.
Communication is successful if both the sender and receiver are run on the same machine. But when they are run different machines communication fails. Also this does not seems to be the issue with Hazelcast Cluster manager (which we used) because hazelcast correctly discovers the other peer on both machine (this is evident from the console logs of hazelcast).
Members [2] {
Member [192.168.43.12]:5701
Member [192.168.43.84]:5701 this
}
Also firewall has not been enabled on both machines, and we were able to establish communication between the same machines using only hazelcast(without using vertx), and it worked perfectly (for example this). So probably the issue is with vert-x.
Upvotes: 4
Views: 663
Reputation: 556
Hazelcat communication is different from Vert.x communication. From the documentation
"Cluster managers do not handle the event bus inter-node transport, this is done directly by Vert.x with TCP connections."
When deploying, you can set the event bus to be in clustered mode. From this on the documentation,
The event bus doesn’t just exist in a single Vert.x instance. By clustering different Vert.x instances together on your network they can form a single, distributed event bus.
With respect to clustering the event bus, the documentation says
The EventBusOptions also lets you specify whether or not the event bus is clustered, the port and host.
When used in containers, you can also configure the public host and port:
Code snippet is
VertxOptions options = new VertxOptions()
.setEventBusOptions(new EventBusOptions()
.setClusterPublicHost("whatever")
.setClusterPublicPort(1234)
);
Vertx.clusteredVertx(options, res -> {
// check if deployment was successful.
Other useful link is this
Upvotes: 0
Reputation: 431
Did you try setting setClustered(true) on VertxOptions? I was testing this example code and it works fine for me:
public static void main(String[] args) {
VertxOptions op = new VertxOptions();
op.setClustered(true);
Vertx.clusteredVertx(op, e -> {
if (e.succeeded()) {
HelloWorldVerticle hwv = new HelloWorldVerticle();
e.result().deployVerticle(hwv);
} else {
e.cause().printStackTrace();
}
});
}
Upvotes: 0