June 2018
Intermediate to advanced
310 pages
6h 32m
English
Now come across a problem, though. Our code resides in the Main.kt file, which grows bigger and bigger. We can start splitting it by using verticles.
You can think of a verticle as a lightweight actor. Let's see an example; look at the following code:
class ServerVerticle: CoroutineVerticle() { override suspend fun start() { val router = router() vertx.createHttpServer().requestHandler(router::accept).listen(8080) } private fun router(): Router { val router = Router.router(vertx) // Our router code comes here now ... return router }}
Now we need to start this verticle. There are different ways of doing that, but the simplest way is to pass the instance of this class to the deployVerticle() method:
vertx.deployVerticle(ServerVerticle()) ...Read now
Unlock full access