Skip to main content

Verticles

A verticle is the basic unit of execution in Vert.x: a class that holds code and is deployed in a Vert.x application. Verticles handle events asynchronously on an event loop.

Characteristics​

  • Unit of execution. A verticle represents a task or a component: serving requests, reaching a database, talking to another service.
  • Asynchronous. It reacts to events, such as messages, through handlers, and never blocks a thread.
  • Flexible deployment. One or several verticles can be deployed on different threads or nodes; Vert.x passes messages between them on the event bus.
  • Isolated state. A verticle shares no state directly with others, which makes concurrent code safer.

Kinds of verticle​

KindUse
StandardExtends AbstractVerticle and defines what happens at startup and shutdown in start() and stop()
WorkerRuns on a thread pool, for blocking work that must not run on the event loop

Example​

public class MyVerticle extends AbstractVerticle {

@Override
public void start() {
// Runs when the verticle starts
vertx.eventBus().consumer("my.address", message -> {
message.reply("Hello from Verticle!");
});
}

@Override
public void stop() {
// Runs when the verticle stops
}
}

This verticle listens for messages sent to my.address on the event bus and replies to each. See Event bus.