Vert.x Core is a high-performance, reactive application toolkit for the JVM providing fundamental building blocks for asynchronous I/O operations.
npx @tessl/cli install tessl/maven-io-vertx--vertx-core@4.5.0Vert.x Core is a high-performance, reactive application toolkit for the JVM that provides fundamental building blocks for creating modern, scalable applications. It offers comprehensive support for asynchronous I/O operations including HTTP/HTTPS servers and clients, TCP networking, file system access, event bus messaging, and WebSocket communication, all built on top of Netty for maximum performance.
pom.xml:<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.5.14</version>
</dependency>import io.vertx.core.Vertx;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import io.vertx.core.Verticle;
import io.vertx.core.AbstractVerticle;import io.vertx.core.Vertx;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
public class BasicExample extends AbstractVerticle {
@Override
public Future<Void> start() {
// Create HTTP server
return vertx.createHttpServer()
.requestHandler(request -> {
request.response()
.putHeader("content-type", "text/plain")
.end("Hello from Vert.x!");
})
.listen(8080)
.mapEmpty();
}
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new BasicExample());
}
}Vert.x Core is built around several key components:
Main entry points, verticle deployment, future composition, and asynchronous execution patterns. Essential for all Vert.x applications.
// Main Vertx factory methods
static Vertx vertx();
static Vertx vertx(VertxOptions options);
static Future<Vertx> clusteredVertx(VertxOptions options);
// Future composition and handling
interface Future<T> extends AsyncResult<T> {
Future<T> onSuccess(Handler<T> handler);
Future<T> onFailure(Handler<Throwable> handler);
Future<T> onComplete(Handler<AsyncResult<T>> handler);
<U> Future<U> compose(Function<T, Future<U>> successMapper);
<U> Future<U> map(Function<T, U> mapper);
Future<T> recover(Function<Throwable, Future<T>> mapper);
}
// Promise for completing futures
interface Promise<T> extends Handler<AsyncResult<T>> {
void complete(T result);
void fail(Throwable cause);
Future<T> future();
boolean tryComplete(T result);
boolean tryFail(Throwable cause);
}Full-featured HTTP 1.1/2.0 client and server with WebSocket support, request/response handling, and streaming capabilities.
// HTTP Server creation and configuration
HttpServer createHttpServer();
HttpServer createHttpServer(HttpServerOptions options);
interface HttpServer extends Measured, Closeable {
HttpServer requestHandler(Handler<HttpServerRequest> handler);
Future<HttpServer> listen(int port);
Future<HttpServer> listen(int port, String host);
HttpServer webSocketHandler(Handler<ServerWebSocket> handler);
}
// HTTP Client creation and requests
HttpClient createHttpClient();
HttpClient createHttpClient(HttpClientOptions options);
interface HttpClient extends Measured, Closeable {
Future<HttpClientRequest> request(HttpMethod method, int port, String host, String requestURI);
Future<HttpClientResponse> get(int port, String host, String requestURI);
Future<HttpClientResponse> post(int port, String host, String requestURI);
}Low-level TCP client/server networking with comprehensive SSL/TLS support, DNS resolution, and UDP datagram communication.
// TCP Server and Client creation
NetServer createNetServer();
NetServer createNetServer(NetServerOptions options);
NetClient createNetClient();
NetClient createNetClient(NetClientOptions options);
// DNS Client creation
DnsClient createDnsClient();
DnsClient createDnsClient(int port, String host);
DnsClient createDnsClient(DnsClientOptions options);
// UDP/Datagram Socket creation
DatagramSocket createDatagramSocket();
DatagramSocket createDatagramSocket(DatagramSocketOptions options);
interface NetServer extends Measured, Closeable {
NetServer connectHandler(Handler<NetSocket> handler);
Future<NetServer> listen(int port);
Future<NetServer> listen(int port, String host);
}
interface NetClient extends Measured, Closeable {
Future<NetSocket> connect(int port, String host);
Future<NetSocket> connect(SocketAddress remoteAddress);
}
interface DnsClient {
Future<String> lookup(String name);
Future<List<String>> resolveA(String name);
Future<List<MxRecord>> resolveMX(String name);
Future<String> reverseLookup(String ipaddress);
}
interface DatagramSocket extends Measured, Closeable {
Future<DatagramSocket> send(Buffer packet, int port, String host);
Future<DatagramSocket> listen(int port, String host);
DatagramSocket handler(Handler<DatagramPacket> handler);
}Distributed messaging system for inter-verticle and inter-node communication with publish/subscribe and request/response patterns.
// Event Bus access and messaging
EventBus eventBus();
interface EventBus extends Measured {
EventBus send(String address, Object message);
EventBus publish(String address, Object message);
<T> Future<Message<T>> request(String address, Object message);
<T> MessageConsumer<T> consumer(String address);
<T> MessageConsumer<T> consumer(String address, Handler<Message<T>> handler);
}
interface Message<T> {
String address();
MultiMap headers();
T body();
void reply(Object message);
void fail(int failureCode, String message);
}Comprehensive asynchronous file system operations including file I/O, directory management, and file watching.
// File System access
FileSystem fileSystem();
interface FileSystem {
Future<Buffer> readFile(String path);
Future<Void> writeFile(String path, Buffer data);
Future<Void> copy(String from, String to);
Future<Void> move(String from, String to);
Future<Void> delete(String path);
Future<AsyncFile> open(String path, OpenOptions options);
Future<List<String>> readDir(String path);
}
interface AsyncFile extends ReadStream<Buffer>, WriteStream<Buffer> {
Future<Void> close();
Future<Buffer> read(Buffer buffer, int offset, long position, int length);
Future<Void> write(Buffer buffer, long position);
}JSON processing, buffer operations, reactive streams, shared data, CLI support, and other utility functionality.
// Buffer operations
interface Buffer extends ClusterSerializable, Shareable {
static Buffer buffer();
static Buffer buffer(String string);
static Buffer buffer(byte[] bytes);
Buffer appendString(String str);
Buffer appendBuffer(Buffer buff);
String getString(int start, int end);
JsonObject toJsonObject();
}
// JSON processing
class JsonObject implements Iterable<Map.Entry<String,Object>> {
JsonObject put(String key, Object value);
<T> T getValue(String key);
String getString(String key);
Integer getInteger(String key);
JsonObject getJsonObject(String key);
String encode();
}// Core execution contexts and handlers
interface Context {
void runOnContext(Handler<Void> action);
<T> void executeBlocking(Handler<Promise<T>> blockingCodeHandler, Handler<AsyncResult<T>> resultHandler);
boolean isEventLoopContext();
boolean isWorkerContext();
}
@FunctionalInterface
interface Handler<E> {
void handle(E event);
}
// Asynchronous result handling
interface AsyncResult<T> {
T result();
Throwable cause();
boolean succeeded();
boolean failed();
}
// Verticle deployment and lifecycle
interface Verticle {
Vertx getVertx();
void init(Vertx vertx, Context context);
Future<Void> start();
Future<Void> stop();
}
// Configuration options base classes
class VertxOptions {
VertxOptions setEventLoopPoolSize(int eventLoopPoolSize);
VertxOptions setWorkerPoolSize(int workerPoolSize);
VertxOptions setBlockedThreadCheckInterval(long blockedThreadCheckInterval);
VertxOptions setHAEnabled(boolean haEnabled);
}
class DeploymentOptions {
DeploymentOptions setConfig(JsonObject config);
DeploymentOptions setWorker(boolean worker);
DeploymentOptions setInstances(int instances);
DeploymentOptions setThreadingModel(ThreadingModel threadingModel);
}
// Threading models
enum ThreadingModel {
EVENT_LOOP, WORKER, VIRTUAL_THREAD
}