Eclipse Vert.x is a microservice development framework based on events and asynchronous, relying on the fully asynchronous Java server Netty, and extends many other features. It is favored by developers for its lightweight, high performance, and support for multi-language development.
Eclipse Vert.x 4.5.0 is now available , and this version brings several new features, including virtual thread support. Highlights updated as follows:
virtual thread
A virtual thread verticle can wait on Vert.x futures and get the results synchronously.
Verticle verticle = new AbstractVerticle() {
@Override
public void start() {
HttpClient client = vertx.createHttpClient();
HttpClientRequest req = Future.await(client.request(
HttpMethod.GET,
8080,
"localhost",
"/"));
HttpClientResponse resp = Future.await(req.send());
int status = resp.statusCode();
Buffer body = Future.await(resp.body());
}
};
// Run the verticle a on virtual thread
vertx.deployVerticle(verticle, new DeploymentOptions().setThreadingModel(ThreadingModel.VIRTUAL_THREAD));
Vert.x virtual threads can be used await
to block any Vert.x future:
// create a test table
await(pool.query("create table test(id int primary key, name varchar(255))").execute());
// insert some test data
await(pool.query("insert into test values (1, 'Hello'), (2, 'World')").execute());
// query some data
RowSet<Row> rows = await(pool.query("select * from test").execute());
for (Row row : rows) {
System.out.println("row = " + row.toJson());
}
More information can be found in the example repo .
Dynamic SQL connection creation
By default, the connection pool always connects to the same host, in other words, the database configuration is static . Sometimes the database configuration needs to be dynamic, such as connecting to a database array, or the database configuration may change.
You can easily achieve this in Vert.x through dynamic connection configuration :
Pool pool = PgBuilder.pool()
.with(poolOptions)
.connectingTo(() -> {
Future<SqlConnectOptions> connectOptions = retrieveOptions();
return connectOptions;
})
.using(vertx)
.build();
Every time the pool needs to create a connection, the options supplier is called and the returned options are used to create the connection.
PG bouncer transaction pooling mode
Level 7 proxies can balance query load across multiple connections to the real database. When this happens, the client may become confused due to lack of session affinity, and unnecessary errors may occur, such as ERROR: unnamed preded statements does not exit (26000).
The Vert.x SQL client now supports level 7 proxies such as PgBouncer .
TCP SSL options update
TCP client/server SSL options can now be updated at runtime , which is useful for certificate rotation.
Future<Boolean> fut = server.updateSSLOptions(
new SSLOptions()
.setKeyCertOptions(new JksOptions()
.setPath("/path/to/your/server-keystore.jks")
.setPassword("password-of-your-keystore")));
New connections will use the updated configuration.
WebSocket client
The WebSocket client API is captured from the Vert.x HTTP client in the new WebSocket client .
WebSocketClient wsClient = vertx.createWebSocketClient();
Future<WebSocket> f = wsClient.connect(connectOptions);
The purpose of this change is to HttpClient
focus the interface on HTTP interactions and clean up the interface.
Client builders
The builder pattern for advanced client creation was introduced in 4.5.
The builder pattern helps configure and create Vert.x clients when they require configuration beyond options.
More details can be found on the official blog .