Futuregen Skill | Best Big Data and Java Blogs and Websites To Follow in 2023 | No.1 Online IT Training in Haldwani, Uttrakhand

OVERVIEW OF ALL BLOGS

12.jpg <

Vert.x

Description

VERT.X

What is Vert.x?

Vert.x is an event-driven, non-blocking reactive applications or system framework running on the JVM and graalvm. Vert.x is polyglot, which mean that it supports many different programming languages. Currently are supported: Java, JavaScript, Ruby, Python, Groovy, Scala and more. Vert.x is known for its easy scalability and lightweight architecturewhich result in very good performance. Vert.x use Netty for all IO-related processes.

What is special about Vert.x?

Vert. x is a great framework when you want a non-blocking strategy for an event-driven applications. When you deal with web application, you usually handle every single request in its own thread. This results in a lot of threads, most of them blocked, which can create much overhead. Vert.x approaches this problem by creating a fixed number of threads (event loops, mostly equivalent to the number of available CPU cores) which handle the requests using an event-based system. This means, everything works with event handlers and callbacks and you are not supposed to do any thread-blocking work directly in those threads. Instead you register a callback to be called after the task has finished.You may think that you can develop the application, but you will have problems with the concurrency when querying the database. But don't worry, because there are some non-blocking connectors.

 

How does it work?

You can create so-called  verticles  which contain your application’s main entry point. Your application can consist of multiple verticles. These verticles are executed within a Vert.x instance and managed by an event loop. The Vert.x instance is running directly on the JVM.At every loop the event loop checks if there are requests available for the verticle. If so, the event loop calls the verticle’s event handler synchronously. The event loops are managed by the Vert.x instance. Usually, you have one event loop running for each processor core with one verticle running on each event loop. But you are free to start more event loops or assign more verticles to one loop. The verticles are connected by an event bus, which they use to send and receive their data. The bus also provides an interface to communicate with each other, even across multiple Vert.x instances or in a cluster. For most usually blocking tasks you can install special busmods (e.g. a MongoDB Persistor) instead of using the usual (blocking) database connectors. If there is no busmod available, you can start worker threads which work asynchronously to the event loops. But if you have to start a worker thread for every request, you should probably use a different framework. You are not supposed to run blocking tasks synchronously, because they would slow down or even block the entire event loop.

How does it look like?

This is how Vert.x looks like with Java:

public class Demo {
  public static void main(String... args) {
    Vertx vertx = Vertx.vertx();
    vertx.createHttpServer().requestHandler(req -> {
      if (req.method() == HttpMethod.GET) {
        if (req.path().equals("/hello")) {
          req.response().end("Hello world.");
        }
      }
    }).listen(8080);
  }
}

What should I use?

That depends on your use case and your personal preferences. If you like annotations and are familiar with Spring, you might not 
need to learn Vert.x. If you need some exorbitant performance, you should consider Vert.x. Spring Boot handles every request in its 
own thread which might be appropriate, if you have to handle complex business logic at many requests. In Vert.x you would have to start 
worker threads for all this which would nullify the performance benefit. But if most of your requests are just requesting semi-dynamic or 
static web pages anyway, you might be better off with Vert.x performancewise. On the other hand, if you have many shared resources, you 
could have a very bad time synchronizing them across all your parallel processes in Spring, while Vert.x makes them easier to manage.

Why Vert.x is Today’s Fastest Framework

Vert.x is ideally a good choice if you want to go for creating lightweight scalable high-performance microservices. If you have to do integrations with rest or other protocols, then it is really easy with Vert.x. It has distributed data structures. For instance, if you have to share your session data of multiple nodes, you can use the same mechanism that is used for messaging. So, underneath it uses Hazelcast which is like a distributed key-value store.

In Vert.x 3.3, they have added more Microservices related features:

Support of Circuit Breaker 
Http2 Web client support 
Service discovery features

 

  • Share

    Category

  • Admissions
  • News
  • Event
  • Tutorials
  • Tech Trends

Recent Posts

s1.jpg
Kubernetes Vs. Openshift vs Docker Swarm
16 March
s1.jpg
Cybersecurity Mesh
16 March
s1.jpg
Data Fabric-Future of Technology
19 February
s1.jpg
Microservice Architecture
14 January