Search code examples
javadesign-patternsvert.xevent-busvertx-verticle

Which message communication pattern is used in generated Vertx Service Proxy classes?


can somebody please clarify which type of message communication patterns:

  1. Point-To-Point
  2. Request-Reply
  3. Publish/Subscribe ... is used in GENERATED Vert.X Service Proxy classes for RESTful CRUD app (which has 4 HttpServerVerticles which communicates with DatabaseVerticle and those are deployed by MainVerticle)? Thank you in advance.

I persume it's Request-Reply since it sends Http Request and recieves Http Response since in "Vert.x in action" it states (in Chapter 3.1.4):

If you need message consumers to get back to the entity that sent the event then go for request-reply. 

Any help/advice is greatly appreciated.


Solution

  • TL;DR: Request-Reply

    If you look in the docs for service proxy (https://vertx.io/docs/vertx-service-proxy/java/) you can see in the beginning that it saves you from doing the following "boiler-plate" code:

    JsonObject message = new JsonObject();
    message.put("collection", "mycollection")
        .put("document", new JsonObject().put("name", "tim"));
    DeliveryOptions options = new DeliveryOptions().addHeader("action", "save");
    vertx.eventBus().request("database-service-address", message, options, res2 -> {
      if (res2.succeeded()) {
        // done
      } else {
        // failure
      }
    });
    

    Also from the same link:

    A service is described with a Java interface containing methods following the async pattern. Under the hood, messages are sent on the event bus to invoke the service and get the response back. But for ease of use, it generates a proxy that you can invoke directly (using the API from the service interface).