Vert.x Service Proxy 类中使用了哪种消息通信模式?

huangapple go评论140阅读模式
英文:

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

问题

可以有人请澄清消息通信模式的哪种类型

  1. 点对点
  2. 请求-回复
  3. 发布/订阅
    ... 在生成的 Vert.X 服务代理类中用于 RESTful CRUD 应用程序(该应用程序有 4 个 HttpServerVerticles,它们与 DatabaseVerticle 通信,并由 MainVerticle 部署)?
    提前感谢您。

我认为应该是请求-回复,因为它发送 Http 请求并接收 Http 响应,正如在《Vert.x 实战》中所述(在第3.1.4章):

如果需要消息消费者回到发送事件的实体,那就选择请求-回复。

非常感谢任何帮助/建议。

英文:

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.

答案1

得分: 2

TL;DR: 请求-回复

如果您查看服务代理的文档(https://vertx.io/docs/vertx-service-proxy/java/),您可以在开头看到它可以帮您省去以下 "样板" 代码:

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()) {
    // 完成
  } else {
    // 失败
  }
});

同样来自相同的链接:

服务是通过包含遵循异步模式的方法的Java接口来描述的。在底层,消息通过事件总线发送以调用服务并获取响应。但为了简化使用,它生成了一个代理,您可以直接调用(使用服务接口的API)。

英文:

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).

huangapple
  • 本文由 发表于 2020年8月10日 21:36:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/63341326.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定