chapter two

2 Verticles: the basic processing units of Vert.x

 

This chapter covers:

  • What verticles are,
  • How to write, configure and deploy verticles,
  • The Vert.x threading model,
  • How to mix Vert.x and non-Vert.x threads.

Put simply, a verticle is the fundamental processing unit in Vert.x. The role of a verticle is to encapsulate a technical functional unit for processing events such as exposing a HTTP API and responding to requests, providing a repository interface on top of a database, or issuing requests to a third-party system. Much like components in other technologies like Enterprise Java Beans, verticles can be deployed, and they have a life-cycle.

Readers familiar with the actor concurrency model will find similarities between Vert.x verticles and actors [ActorModel]. Put simply, actors are a model where autonomous entities (the actors) exclusively communicate with other entities by sending and responding to messages. The similarities between Vert.x verticles and actors is no fortuitous coincidence: verticles have private state that may be updated when receiving events, they can deploy other verticles, and they can communicate via message-passing (more on that in the next chapter). Verticles do not necessarily follow the orthodox modern definition of actors, but it is fair to consider Vert.x at least as being inspired by actors.

Let us now dive into writing verticles.

2.1  Writing a verticle

2.1.1  Preparing the project

2.1.2  The verticle class

2.1.3  Running and first observations

2.2  More on verticles

2.2.1  Blocking and the event-loop

2.2.2  Asynchronous notification of life-cycle events

2.2.3  Deploying verticles

2.2.4  Passing configuration data

2.3  When code needs to block

2.3.1  Worker verticles

2.3.2  The executeBlocking operation

2.4  So what is really in a verticle?

2.4.1  Verticles and their environment

2.4.2  More on contexts

2.4.3  Bridging Vert.x and non-Vert.x threading models

2.5  Summary

2.6  References