Java - Vert.X Framework

1 - About

Vert.x is not a framework but a toolkit: the core library defines the fundamental APIs for writing asynchronous networked applications, and then you can pick the useful modules for your application (e.g., database connection, monitoring, authentication, logging, service discovery, clustering support, etc). Vert.x is based on the Netty project.

Vert.x implements the reactor pattern. In practice, this means many concurrent requests can be handled by the same thread, thus preventing usage of ThreadLocals to store contextual data.

Vert.x is an event-driven, reactive, non-blocking, polyglot framework to implement microservices.

Because Vert.x was designed for asynchronous communications it can deal with more concurrent network connections with less threads than synchronous APIs such as:

The code is already written for scaling up: asynchronous processing of events.

2 - Usage

  • high volume message
  • event processing,
  • micro-services,
  • API gateways,
  • HTTP APIs for mobile applications,
  • etc

3 - Concept

Two concepts:

Vert.x is almost entirely non-blocking (of kernel threads) - this allows it to handle a lot of concurrency (e.g. handle many connections, or messages) using a very small number of kernel threads, which allows it to scale very well.

4 - Threading model

4.1 - Synchronous

Synchronous I/O: Many networking libraries and frameworks rely on a simple threading strategy: each network client is being assigned a thread upon connection, and this thread deals with the client until it disconnects. This is the case

  • with Servlet
  • or networking code written with the java.io and java.net packages

Too many concurrent connections will hurt scalability as system threads are not cheap, and under heavy loads an operating system kernel spends significant time just on thread scheduling management.

4.2 - Asynchronous

A verticle processes incoming events over an event-loop, where events can be anything like receiving network buffers, timing events, or messages sent by other verticles.

4.3 - Module

  • web (http)
  • Vert.x JDBC client to provide an asynchronous API over JDBC. - provides access to any JDBC-compliant database
  • MySQL and PostgreSQL client libraries - these libraries offers better performance by working with these 2 database server network protocols rather than going through the (blocking) JDBC APIs.
  • Apache Cassandra, OrientDB or ElasticSearch

4.4 - Launching a verticle

5 - App

  • Verticle

package examples.vertx;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;

public class MyVerticle extends AbstractVerticle {

    @Override
    public void start(Future<Void> startFuture) {
        System.out.println("MyVerticle started!");
    }

    @Override
    public void stop(Future stopFuture) throws Exception {
        System.out.println("MyVerticle stopped!");
    }

}

  • Main

import io.vertx.core.Vertx;

public class VertxApp {

    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();
        vertx.deployVerticle(new MyVerticle());
    }

}

6 - Installation

https://vertx.io/download/

the Vert.x command line makes it easy to deploy verticles implemented in different programming languages in the same Vertx instance.


vertx -version
vertx run javascript:my-verticle.js
vertx run com.package.MyVerticle -cp MyVerticle.jar;thirdLib.jar

7 - Documentation


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap