[英]What do you consider as verticle design guideline in Vert.x?
While the core manual (and other documentation) of Vert.x shows several use cases and gives good explanations of Vert.x in general, I am curious what are do and donts when designing verticle classes.虽然 Vert.x 的核心手册(和其他文档)展示了几个用例并对 Vert.x 给出了很好的解释,但我很好奇在设计 Verticle 类时应该做什么和不应该做什么。
Preword : I am aware of that the design of Vert.x is in general AGAINST giving strict design guidelines.前言:我知道 Vert.x 的设计通常是反对给出严格的设计指南的。 So, no need to mention this in answers.
因此,无需在答案中提及这一点。
An example that led me to this question is as following.导致我提出这个问题的一个例子如下。 I created a verticle named ServiceDiscoveryVerticle.java which has the following responsibilities:
我创建了一个名为ServiceDiscoveryVerticle.java的 Verticle,它具有以下职责:
All this is code is manifested in the overriden start method.所有这些代码都体现在重写的 start 方法中。
So the core questions I ask in this questions are:所以我在这个问题中提出的核心问题是:
One can do a lot of philosophy here, but I will try to keep it simple.在这里可以做很多哲学,但我会尽量保持简单。
The fact is that a verticle and its start()
is and will be the main way that you init your system, mount handlers, trigger things like loading config and co.事实上,verticle 及其
start()
是并且将是您初始化系统、挂载处理程序、触发加载配置和 co 等事情的主要方式。 So don't be too hard on yourself, this part is correct.所以不要对自己太苛刻,这部分是正确的。
If you are using Web Service API or Service Proxy then handlers are mounted automatically for you.如果您使用的是 Web 服务 API 或服务代理,则会自动为您安装处理程序。 The actual code of these handlers are in external classes that you can decide on how to structure them.
这些处理程序的实际代码位于外部类中,您可以决定如何构建它们。
If you are mounting your handlers on your own, then you can use a lot of inline code, or you can decide to extract them into classes.如果您自己安装处理程序,那么您可以使用大量内联代码,或者您可以决定将它们提取到类中。 In a lager application however you will probably split and extract code as much as you can.
然而,在更大的应用程序中,您可能会尽可能多地拆分和提取代码。
I personally extract code out of verticle as much as I can and make it a rather coordination and setup place.我个人尽可能多地从 Verticle 中提取代码,并使其成为一个相当协调和设置的地方。 Also my
start()
method (or rather rxStart()
) is a bunch of calls to other methods who's names give me an overview of what is going on in the start of system rather than having a lot of code that I can't read.另外,我的
start()
方法(或者更确切地说rxStart()
)是对其他方法的一堆调用,这些方法的名字让我对系统启动时发生的事情有一个概述,而不是有很多我看不懂的代码. But these are all personal preferences as you said.但正如你所说,这些都是个人喜好。 Vert.x does not imply any of it on you!
Vert.x 并不暗示你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.