英文:
Which message communication pattern is used in generated Vertx Service Proxy classes?
问题
可以有人请澄清消息通信模式的哪种类型:
- 点对点
- 请求-回复
- 发布/订阅
... 在生成的 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:
- Point-To-Point
- Request-Reply
- 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
. But for
> event bus to invoke the service and get the response back
> ease of use, it generates a proxy that you can invoke directly (using
> the API from the service interface).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论