This is a port of vertx3-eventbus-client.js writen in Java.
EventBus eventBus = EventBusAdapter.connect("ws://localhost/eventbus/websocket");
eventBus.onOpen(new ConnectionHandler() {
@Override
public void handle() {
// handle on connection open
}
});
eventBus.onClose(new ConnectionHandler() {
@Override
public void handle() {
// handle on connection closed
}
});
eventBus.open();
eventBus.registerHandler("chat.message.123", new MessageHandler() {
@Override
public void handle(Message message) {
System.out.println("I have received a message: " + message.body());
}
});
eventBus.publish("chat.message", "Hello");
eventBus.send("chat.token", null, null, new ReplyHandler() {
@Override
public void handle(Message message) {
System.out.println("Received reply: " + message.body());
}
});