June 2018
Intermediate to advanced
310 pages
6h 32m
English
What's left is only to call the cat from the ServerVerticle. For that, we'll add another method to our CoroutineVerticle:
fun <T> CoroutineVerticle.send(address: String, message: T, callback: (AsyncResult<Message<T>>) -> Unit) { this.vertx.eventBus().send(address, message, callback)}
Then we can handle our request like this:
...router.get("/cats").asyncHandler { ctx -> send(CATS, ctx.queryParams().toJson()) { it.handle({ val responseBody = it.result().body() ctx.respond(responseBody.get<JsonArray>("rows").toString()) }, { ctx.respond(status=500) }) }}...
Notice that we're reusing the same constant we defined earlier, called CATS.
That way, we can easily check who can send this event and who consumes it. If it's successful, we'll ...
Read now
Unlock full access