Skip to content

What it is

Vert.x is a toolkit for building reactive, non-blocking, and polyglot applications on the JVM. It supports asynchronous programming, event-driven architecture, and high-performance microservices.

Vert.x allows developers to create HTTP servers, clients, event buses, and reactive streams using an asynchronous API. It supports multiple JVM languages, modular architecture, and clustering for high availability.

Installation

Add io.vertx:vertx-core dependency in pom.xml

Getting started

The smallest useful thing you can do with it, and what each part means.

Creating a simple HTTP server
import io.vertx.core.Vertx;

Vertx vertx = Vertx.vertx();
vertx.createHttpServer().requestHandler(req -> {
    req.response().end("Hello Vert.x!");
}).listen(8080);
Creates a basic HTTP server that responds with 'Hello Vert.x!' on port 8080.
Deploying a Verticle
import io.vertx.core.AbstractVerticle;

public class MyVerticle extends AbstractVerticle {
    @Override
    public void start() {
        vertx.createHttpServer().requestHandler(req -> {
            req.response().end("Hello from verticle!");
        }).listen(8081);
    }
}

vertx.deployVerticle(new MyVerticle());
Deploys a verticle, the core unit of deployment in Vert.x, which handles server logic asynchronously.

Advanced usage

Where the library earns its place over a simpler alternative.

Using Event Bus
vertx.eventBus().consumer("news", message -> {
    System.out.println("Received: " + message.body());
});
vertx.eventBus().publish("news", "Breaking news!");
Demonstrates publishing and consuming messages via Vert.x event bus for inter-verticle communication.
Asynchronous HTTP client
vertx.createHttpClient().getNow(8080, "localhost", "/", response -> {
    response.bodyHandler(body -> {
        System.out.println("Received: " + body.toString());
    });
});
Shows how to make non-blocking HTTP requests using Vert.x asynchronous client.
Reactive Streams with Vert.x
import io.vertx.core.streams.Pump;
Pump.pump(source, destination).start();
Demonstrates bridging streams for backpressure-aware data flow using Vert.x reactive APIs.
Clustering Vert.x
Vertx.clusteredVertx(new VertxOptions().setClustered(true), res -> {
    if (res.succeeded()) {
        Vertx vertxClustered = res.result();
    }
});
Enables Vert.x clustering for distributed event bus and high availability.

Errors and fixes

The failures you are most likely to hit, and what actually resolves them.

Handler not called
Ensure the event loop is not blocked and the handler is registered before events are published.
Port already in use
Use a different port or ensure no other process is listening on the same port.
Verticle deployment failed
Check for exceptions in start() method; verify dependencies and configurations.

Best practices

  • Use verticles to encapsulate logic and deploy independently.
  • Leverage the event bus for communication between verticles.
  • Avoid blocking operations; use asynchronous APIs for I/O tasks.
  • Use configuration files or environment variables for deployment settings.
  • Organize code modularly for maintainability in microservices architectures.

Background

Why it exists, and what it was reacting to.

Vert.x was created to provide a lightweight and scalable platform for building reactive applications. It leverages the event loop model, similar to Node.js, for handling concurrent I/O operations efficiently, making it ideal for web, microservices, and real-time applications.