Share
Embed
Vert.x 5 news and roadmap
Eclipse Vert.x helps you create reactive applications on the JVM. It’s lightweight, flexible and designed to make reactive programming an approachable experience, without sacrificing performance.
Join us for an insightful presentation on the upcoming Vert.x 5 release, where we will explore some of its exciting new features and how it has evolved alongside significant changes in the Java Development Kit.
If you are new to Vert.x, no worries, we will start with a short introduction of the toolkit. As an experienced user, you will learn why it remains an excellent choice in 2024 to implement your applications.
Thomas Segismont
October 05, 2024
Transcript
51 slides
-
1 Eclipse Vert.x 5 News and roadmap Thomas Segismont Principal
Software Engineer -
What we’ll discuss today Agenda 2 ▸ Recap on Vert.x
▸ Cleanups ▸ Adapting to JDK changes ▸ New features ▸ Vert.x 5.0 and beyond -
In perspective 4 Node.js 2009 2010 Kafka 2011 2013 2014
Vert.x Docker Reactive Manifesto Microservices Kubernetes -
5 Monoliths, microservices Deployment Agility Bare metal, virtual machines, containers
New use cases From backoffice to “webscale” An evolving IT landscape -
Applications that involve a variety of network interactions ▸ RDBMS
▸ NoSQL ▸ External API (HTTP or gRPC) 6 Many applications colocated and sharing virtual resources ▸ vCPU ▸ (Relatively) small heaps The new normal An evolving IT landscape -
Traditional pattern : thread per request 7 Request 1 Request
2 Request n Pooled thread Pooled thread Pooled thread -
Reactor pattern : one event loop 8 Event loop thread
Request 1 Request 2 Request 3 -
Multi-reactor pattern : several event loops 9 Event loop thread
Event loop thread Event loop thread -
10 ▸ Toolkit ▸ Comprehensive stack ▸ Lightweight actor-like model
with the EventBus ▸ Choose your programming style The Vert.x proposal -
The verticle unit of deployment 11 public class Server extends
VerticleBase { public static void main(String[] args) { Vertx.vertx() .deployVerticle(Server::new, new DeploymentOptions().setInstances(4)) .await(); } @Override public Future<?> start() throws Exception { Router router = Router.router(vertx); router.get().handler(routingContext -> { routingContext.response().putHeader("content-type", "text/html").end("Hello World!"); }); return vertx.createHttpServer() .requestHandler(router) .listen(8080); } } The returned future is completed when the server is bound Each instance gets its event loop The deployment unit -
Use cases 12 Vert.x is versatile ▸ Webapps (Vert.x Web,
templates, Sql Clients, Web Client, ...etc) ▸ Microservices (Health checks, Circuit breaker, Discovery, ...etc) ▸ IoT (MQTT, Messaging clients) What can you do with Vert.x? -
Use cases 13 Protocol adapters Phone call to bank 2.0
Legacy App Adapter Balance Service gRPC Account Service REST Transfer Service AMQP Service Provider Bank TCP -
Use cases 14 Edge service / API Gateway Streamline WAN
calls Browser App Cart Service gRPC Product Service REST Review Service AMQP Customer Data center API Gateway REST gRPC Mobile App -
Use cases 15 Microservices HTTP and/or Kafka Kafka Cart Service
Product Service Review Service REST gRPC REST Webapp Mobile backend -
Use cases 17 Streaming data Dashboards Customer (Browser) Relay Order
service AMQP Websockets Customer (Device) SSE Supervisor (Browser) Kafka Delivery Worker (Device) Location service -
Use cases 18 ▸ CRUD application ▸ Single network interaction
▸ Integrating only blocking code When not to use Vert.x -
20 Callbacks removal getNameAsync(ar1 -> { if (ar1.succeeded()) { sayHelloAsync(ar1.result(),
ar2-> { if (ar2.succeeded()) { String greeting = ar2.result(); // Do something } else { // Handle failure } }); } else { // Handle failure } }); Future<String> greetingFuture = getNameAsync() .compose(name -> sayHelloAsync(name)); // Do something with future -
21 CLI framework removal vertx run –instances 4 MyVerticle.kt ▸
Most apps packaged as uber-jars or layered container images ▸ New vertx-launcher-application module ▸ Vert.x Maven Plugin for dev redeployment -
25 Sources: https://openjdk.org/jeps/8305968 https://www.youtube.com/watch?v=wNQKRBLbKIs What is integrity? public final class
EvenCounter { private int x = 0; public int value() { return x; } public void incrementByTwo() { x += 2; } public void decrementByTwo() { x -= 2; } } ▸ Integrity provides: ・ Maintainability ・ Safety (analysis confinement) ・ Performance (JIT, jlink, Leyden optimizations) ▸ Integrity is threatened by: ・ JNI / FFM / Unsafe ・ Java agents ・ setAccessible with reflection -
Vert.x 5 and JPMS ▸ Full JPMS support in Vert.x
5 ・ Mostly dealt with split packages ・ Clearly define “internal API” ▸ Full JPMS support in Netty 4.2 26 “Integrity by default means that every construct of the Java Platform has integrity, unless overridden explicitly at the highest level of the program.” ▸ Strong encapsulation of constructs ▸ Restrictions on unsafe APIs And what it means for Vert.x Integrity by default Sources: https://openjdk.org/jeps/8305968 https://www.youtube.com/watch?v=wNQKRBLbKIs -
28 What is biased locking? public class Counter { private
final Object lock = new Object(); private int value = 0; public int count() { synchronized (lock) { return value; } } public void increment(int val) { synchronized (lock) { value += val; } } } ▸ Remove where it makes sense ▸ Different tools ・ Lock-free algorithms ・ JCTools And we did about it -
30 public class CleaningExample implements AutoCloseable { // A cleaner,
preferably one shared within a library private static final Cleaner cleaner = Cleaner.create(); static class State implements Runnable { // State fields State() { // initialize State needed for cleaning action } public void run() { // cleanup action accessing State, executed at most once } } private final State state; private final Cleaner.Cleanable cleanable; public CleaningExample() { this.state = new State(); this.cleanable = cleaner.register(this, state); } public void close() { cleanable.clean(); } } -
32 Before Future based Verticle deployment contract public class Server
extends AbstractVerticle { @Override public void start(Promise<Void> promise) throws Exception { Router router = Router.router(vertx); router.get().handler(routingContext -> { routingContext.response().putHeader("content-type", "text/html").end("Hello World!"); }); Future<HttpServer> serverFuture = vertx.createHttpServer() .requestHandler(router) .listen(8080); serverFuture.<Void>mapEmpty().onComplete(promise); } } Promise to signal completion Mandatory mapping to the promise param type -
33 After Future based Verticle deployment contract public class Server
extends VerticleBase { @Override public Future<?> start() throws Exception { Router router = Router.router(vertx); router.get().handler(routingContext -> { routingContext.response().putHeader("content-type", "text/html").end("Hello World!"); }); return vertx.createHttpServer() .requestHandler(router) .listen(8080); } } Asynchronous start method Return any future Only the completion matters -
34 Graceful server shutdown public class GracefulShutdownServer extends VerticleBase {
private HttpServer httpServer; @Override public Future<?> start() throws Exception { Router router = Router.router(vertx); router.get().handler(routingContext -> { routingContext.response().putHeader("content-type", "text/html").end("Hello World!"); }); httpServer = vertx.createHttpServer().requestHandler(router); return httpServer.listen(8080); } @Override public Future<?> stop() throws Exception { return httpServer.shutdown(30, SECONDS); } } Store a reference to the server Shutdown instead of auto-closing -
35 ▸ Resolver turns logical addresses in a list of
endpoints ▸ Several built-in load-balancing policies ▸ Default resolver: DNS A or AAAA records ▸ More resolvers in vertx-service-resolver ・ Kubernetes Headless Services ・ DNS SRV records Client-side load-balancing for HTTP (and gRPC) HttpClientAgent client = vertx .httpClientBuilder() // Omit to use the default resolver .withAddressResolver(addressResolver) .withLoadBalancer(LoadBalancer.ROUND_ROBIN) .build(); -
37 gRPC Web - proto file service EchoService { rpc
Echo(EchoRequest) returns (EchoResponse); } message EchoRequest { string message = 1; } message EchoResponse { string message = 1; } -
38 gRPC Web - JavaScript Client var echoService = new
proto.mypackage.EchoServiceClient('http://localhost:8080'); var request = new proto.mypackage.EchoRequest(); request.setMessage(msg); var metadata = {'custom-header-1': 'value1'}; echoService.echo(request, metadata, function(err, response) { if (err) { console.log(err.code); console.log(err.message); } else { console.log(response.getMessage()); } }); Generated by: (protoc-gen-js) protoc-gen-grpc-web -
39 gRPC Web - Vert.x Server GrpcServerOptions options = new
GrpcServerOptions() .setGrpcWebEnabled(true); GrpcServer grpcServer = GrpcServer.server(vertx, options); grpcServer.callHandler(ECHO_SERVICE, request -> { request.handler(requestMsg -> { GrpcServerResponse<EchoRequest, EchoResponse> response = request.response(); String payload = requestMsg.getPayload(); EchoResponse responseMsg = EchoResponse.newBuilder() .setPayload(payload) .build(); response.end(responseMsg); }); }); httpServer = vertx.createHttpServer(new HttpServerOptions().setPort(port)).requestHandler(grpcServer); Enable gRPC Web support No need for a proxy -
41 gRPC client-side deadlines Future<GrpcClientRequest<HelloRequest, HelloReply>> fut = cLient.request(server,SayHello); fut.onSuccess(request
-> { request // Given this request, set a 10 seconds timeout that will be sent to the gRPC service .timeout(10, TimeUnit.SECONDS); request.end(HelloRequest.newBuilder().setName("Bob").build()); }); // Let the client schedule a deadline GrpcClient client = GrpcClient.client(vertx, new GrpcClientOptions() .setScheduleDeadlineAutomatically(true)); Will automatically cancel a request if a timeout is set -
42 gRPC server-side deadline GrpcServer server = GrpcServer.server(vertx, new GrpcServerOptions()
.setScheduleDeadlineAutomatically(true) .setDeadlinePropagation(true) ); Will automatically cancel a request if a timeout is set Will propagate the deadline to requests made with the gRPC Client -
44 io_uring transport VertxOptions options = new VertxOptions() .setPreferNativeTransport(true); Vertx
vertx = Vertx.vertx(options); <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-io_uring-incubator</artifactId> </dependency> -
45 Vert.x HTTP Proxy ▸ Out-of-the-box transformations ▸ Interceptors support
in websocket upgrades ▸ Caching SPI ▸ Extended support of caching specifications -
46 https://vertx.io/blog/micrometer-metrics-performance/ ▸ Fil ter tags up front in stead
of using a Mi crom e ter MeterFilter ▸ Avoid re dun dant copies when com bin ing tags ▸ Look up me ters once if their tags are known in ad vance ▸ Use a MeterProvider when some tags can be de ter mined only after an event oc cured Vert.x Micrometer Metrics performance -
47 Source: https://vertx.io/blog/micrometer-metrics-performance/ Vert.x Micrometer Metrics performance // On startup
MeterProvider<Counter> requestCount = Counter.builder(names.getHttpRequestsCount()) .description("Number of processed requests") .withRegistry(registry); // When the response ends Tags responseTags = Tags.of( "route", request.getRoute(), "code", String.valueOf(response.statusCode()) ); requestCount.withTags(responseTags).increment(); MeterProvider API helps saving a lot of object allocations -
49 Support of HTTP/3 Creative Commons Attribution-Share Alike 4.0 International
license https://en.wikipedia.org/wiki/File:HTTP-1.1_vs._HTTP-2_vs._HTTP-3_Protocol_Stack.svg https://commons.wikimedia.org/wiki/File:Tcp-vs-quic-handshake.svg -
linkedin.com/company/red-hat youtube.com/user/RedHatVideos facebook.com/redhatinc twitter.com/RedHat 51 Red Hat is the world’s
leading provider of enterprise open source software solutions. Award-winning support, training, and consulting services make Red Hat a trusted adviser to the Fortune 500. Thank you