A beginning guide to Vert.x, the main elements, and the main features, like Event Loop, Verticles, and Event Bus. Includes a link to a GitHub repository with samples.
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
Vert.x Event Driven Non Blocking Reactive Toolkit
1. Vert.x – Event Driven Non Blocking Reactive Toolkit
Brian S Paskin, Senior Application Architect, R&D Services, IBM Cloud Innovations Lab
6 April 2020
WebSphere Liberty Lunch and Learn
2. Introduction
2
Vert.x is an open source project by the Eclipse Foundation
Is a reactive toolkit that can used as a serverless implementation or in an application
Used for writing asynchronous network applications
Supported under multiple Java based languages (polyglot)
– Java, Kotlin, JavaScript, Groovy, Ruby, Scala
Has two programming methods, with or without Verticles (spelled that way)
There are different libraries for databases, monitoring, logging, et cetera
Non blocking and event driven that is scalable using an Event Bus
– Uses an Event Loop to process requests
– Event Bus to handle communications between Verticles
– Can span multiple JVMs and systems
Can be used with Quarkus and GraalVM
Requires Maven Shade to create a fat jar
4. Event Loop
4
Implementation of the multi Reactor design pattern
– Continuously checking for new events and pass it to the proper Handler
– Normal Reactor is single threaded, but Vert.x is multi-threaded
Number of threads for the Event Loop depends on the number of processors
– Is equal to 2 * number of processors
– Not based on the number of Verticles deployed
– Threads are assigned in a round robin method for Verticles
Verticles will always execute on the assigned thread
Worker Verticles have their own thread pools
The Context is passed to the Verticle from the Event Loop
– All Handlers in an Event Loop run using the same Context
– Each Context has its own error handler
– Maintains thread safety
Never block the event loop
6. Verticles
6
A Verticle is a unit of deployment
Assigned a Thread in an Event Loop
Each Verticle has an isolated classloader and cannot share global state
Verticles can be passed configuration information
2 Different Types of Verticles
– Standard
– Workers
A standard Verticle should be quick and a non blocking unit of work
A worker Verticle is like a standard Verticle but using a different Thread pool
– Can call blocking code
– Used for limiting number of executions of code (ie. calling backend system)
Can be run in high available mode
– Deploys new Verticle if it dies abruptly
7. Event Bus
7
The Event Bus is used for Verticles to communicate with each other by sending messages
– Single instance per Vert.x instance
– Asynchronous
Can be used with Verticles in the same JVM or across multiple JVMs and systems
– Outside of a single JVM Hazelcast is used to transport messages
Can be used to communicate with JavaScript
Three types of messaging
– Publish and subscribe
– Point to point
– Request – response
Failures in all or part of the Event Bus may lead to lost messages
9. Common Libraries Highlights
9
Core
– Deploy Verticles
– HTTP Server
– Basic Event Bus
– Logging
– JSON and Parser
– Datagrams
– Metrics
– High availability and failover
– Timer events
– Buffers
Web
– Route requests to Handlers and sub routers
– Routing based on criteria (HTTP Method, MIME type, etc.)
– Authentication (OAuth, Basic)
– Serve web pages
– CORS
– Uploads
– Cookie Handling
– Form handling
– Virtual hosts
– SockJS support
10. Common Libraries Highlights
10
Configuration
– Multiple formats (JSON, Properties, YAML, HOCON, System Props, Environment Entries, etc.)
– Can read default configuration file or specify file
– Different configurations can be passed to different Verticles
JDBC Client
MongoDB Client
SQL Common
– Used in conjunction of one of the other data access libraries
Reactive
– Uses RxJava
Circuit Breaks for Micro Services
MQTT
Kafka Client
Mail Client
Serverless implementation – an App Server/Transaction processor is not needed. SpringBoot is serverless.Reactive programming is a programming paradigm, associated with asynchronous streams, which respond to any changes or events.
Vert.x uses an event bus, to communicate with different parts of the application and passes events, asynchronously to handlers when they available.
a verticle is a unit of deployment
Vert.x does not follow the JEE / Jakarta EE standards
Uses Netty and Hazelcast under the covers
Need Maven Shade to create a fat jar.