Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vert.x 5 news and roadmap

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 pro­gram­ming an approachable experience, with­out 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
Tweet

More Decks by Thomas Segismont

Other Decks in Programming

Transcript

  1. What we’ll discuss today Agenda 2 ▸ Recap on Vert.x

    ▸ Cleanups ▸ Adapting to JDK changes ▸ New features ▸ Vert.x 5.0 and beyond
  2. In perspective 4 Node.js 2009 2010 Kafka 2011 2013 2014

    Vert.x Docker Reactive Manifesto Microservices Kubernetes
  3. 5 Monoliths, microservices Deployment Agility Bare metal, virtual machines, containers

    New use cases From backoffice to “webscale” An evolving IT landscape
  4. 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
  5. Traditional pattern : thread per request 7 Request 1 Request

    2 Request n Pooled thread Pooled thread Pooled thread
  6. 10 ▸ Toolkit ▸ Comprehensive stack ▸ Lightweight actor-like model

    with the EventBus ▸ Choose your programming style The Vert.x proposal
  7. 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
  8. 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?
  9. 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
  10. 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
  11. Use cases 15 Microservices HTTP and/or Kafka Kafka Cart Service

    Product Service Review Service REST gRPC REST Webapp Mobile backend
  12. Use cases 17 Streaming data Dashboards Customer (Browser) Relay Order

    service AMQP Websockets Customer (Device) SSE Supervisor (Browser) Kafka Delivery Worker (Device) Location service
  13. Use cases 18 ▸ CRUD application ▸ Single network interaction

    ▸ Integrating only blocking code When not to use Vert.x
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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(); } }
  20. 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
  21. 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
  22. 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
  23. 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();
  24. 37 gRPC Web - proto file service EchoService { rpc

    Echo(EchoRequest) returns (EchoResponse); } message EchoRequest { string message = 1; } message EchoResponse { string message = 1; }
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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>
  30. 45 Vert.x HTTP Proxy ▸ Out-of-the-box transformations ▸ Interceptors support

    in websocket upgrades ▸ Caching SPI ▸ Extended support of caching specifications
  31. 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
  32. 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
  33. 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
  34. 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