-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
PingPong.java
35 lines (27 loc) · 913 Bytes
/
PingPong.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package io.vertx.example.reactivex.eventbus.pingpong;
import io.vertx.core.Launcher;
import io.vertx.reactivex.core.AbstractVerticle;
import io.vertx.reactivex.core.eventbus.EventBus;
public class PingPong extends AbstractVerticle {
private static final String ADDRESS = "ping-address";
public static void main(String[] args) {
Launcher.executeCommand("run", PingPong.class.getName(), "-cluster");
}
@Override
public void start() throws Exception {
EventBus eb = vertx.eventBus();
eb.consumer(ADDRESS)
.toFlowable()
.subscribe(message -> {
System.out.println("Received " + message.body());
message.reply("PONG");
});
// Send a message every second
vertx.setPeriodic(1000, v -> {
eb.rxRequest(ADDRESS, "PING")
.subscribe(reply -> {
System.out.println("Received reply " + reply.body());
});
});
}
}