This example in this module shows the use of 2 verticles communicating with each other. The messages you send with the HTTP Post
requests over the http://localhost:8080/send/:message
are forwarded to the receiver verticle.
/**
*
* @param routingContext
*/
private void sendMessage(RoutingContext routingContext){
final EventBus eventBus = vertx.eventBus();
final String message = routingContext.request().getParam(PATH_PARAM);
eventBus.send(ADDRESS, message, reply -> {
if (reply.succeeded()) {
log.info("Received reply: " + reply.result().body());
} else {
log.info("No reply");
}
});
routingContext.response().end(message);
}
@Override
public void start() throws Exception {
final EventBus eventBus = vertx.eventBus();
eventBus.consumer(ADDRESS, receivedMessage -> {
log.debug("Received message: " + receivedMessage.body());
receivedMessage.reply(DEFAULT_REPLY_MESSAGE);
});
log.info("Receiver ready!");
}
- JDK or later
- Maven 3.0.0 or later
- Maven compiler plugin 3.8.0 or later
sh compile.sh
sh modularJar.sh
java -p ../modularjars:../helper/modules -m messenger
Or
sh run.sh
How to Work With Multiple Verticles and Communication in Vert.x