【发布时间】:2020-06-11 11:00:08
【问题描述】:
我目前正在开发我的第一个 vert.x 服务,但我对我的部署实施方式并不十分自信。
我有几个 Verticle 来接受来自其他服务的请求并将一堆工作委托给其他 Verticle。如何在工作完成后启动每个任务的 verticle 并杀死它,或者以编程方式将 verticles 扩大到任务的数量。
我目前在启动时生成 10 个 Verticle,并使用事件总线将这些任务分散到各个 Verticle 上。
主垂直
class MainVerticle : CoroutineVerticle() {
private val databaseConfig by lazy { config.getJsonObject("migration") }
override suspend fun start() {
vertx.deployVerticle(AdministrationVerticle::class.java, DeploymentOptions().setConfig(config))
vertx.deployVerticle(UpdateVerticle::class.java, DeploymentOptions().setConfig(config))
}
}
管理垂直 - HTTP 处理程序
private suspend fun handleRolloutRequest(ctx: RoutingContext) {
val version = ctx.request().getParam("version")?.toInt() ?: findLatestVersion()
val systems = findOutdatedSystems(version)
for (system in systems) {
vertx.eventBus().send("rollout", system.id, options)
}
ctx.response().end()
}
更新垂直
override suspend fun start() {
client.connectAwait(mqttServerConfig.getInteger("port"), mqttServerConfig.getString("hostname"))
vertx.eventBus().consumer<String>("rollout") {
launch(vertx.dispatcher()) {
// actual rollout
}
}
}
【问题讨论】:
标签: vert.x vertx-verticle actor-model