Skip to content

Files

Latest commit

 

History

History

messenger

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Messenger Module

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.

Sender

   /**
     *
     * @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);
    }

Receiver

    @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!");
    }

Requirements

  • JDK or later
  • Maven 3.0.0 or later
  • Maven compiler plugin 3.8.0 or later

To compile

sh compile.sh

To create modular jar

sh modularJar.sh

To run

java -p ../modularjars:../helper/modules -m messenger

Or

sh run.sh

Relevant article is

How to Work With Multiple Verticles and Communication in Vert.x