Vert.x Ecosystem
Eclipse Vert.x is a open-source, reactive and polyglot framework that is ideal for adopting event-driven design. It shares common functionalities among all the supported languages like Java, Ruby, Kotlin, Scala, and JavaScript. This means that developers can use the language they’re most comfortable with or the one that’s best for their specific project. Vert.x is a toolkit, so we can embed it into our standalone Java application. We can use it by instantiating the object of Vert. Vert.x uses an event bus, to communicate with different parts of the application and passes events, asynchronously to handlers when they available.
The Eclipse Vert.x stack conÂtains modÂules for buildÂing modÂern, end-​to-end reÂacÂtive serÂvices. From efÂfiÂcient reÂacÂtive dataÂbase clients to event streamÂing, mesÂsagÂing and web stacks, the Eclipse Vert.x project has you covÂered:

Basics of Vert.x
Event loop
Imagine you have one thread that is continuously running one infinite while loop executing the following steps:
- In the first step of that loop we are taking the next element from the queue. Event can be anything like receiving network buffers, timing events, messages sent from different sources, etc.
- In the second step, we are finding handler for that event.
- In the third step, event is dispatched to the interested handler.

We should never run blocking code in the event loop.
Verticle
Verticles are deployed and run by Vert.x, we can deploy multiple instances of the same Verticle if the incoming load to that kind of Verticle is larger than one verticle instance can handle. Often you will have a verticle that starts some server that will route the incoming request to different handlers, maybe another verticle for interacting with a database, another for some information coming from some message broker, etc.
There are two types of verticles: regular & worker. Regular verticles are executed on the event loop and thus should never block. Worker verticles are not executed on the event loop, instead, they use worker thread taken from the worker pool. Regular verticles always have the same thread assigned to them, while worker verticles don’t always have the same thread assigned to them.

Event bus
The Event bus is meant for sending and receiving messages in an asynchronous fashion. The most common usage is communication between verticles. Messages are sent to and retrieved from destinations.
The event bus provides three patterns of communication: point-to-point, request-reply & publish/subscribe.
Future/Promises
Promise is used to write an eventual value, and Future is used to read that value when it is available. The promise is created by a piece of code that wants to perform the async operation. From the promise object, we create a future object and register handlers to that future.
Vertx vertx = Vertx.vertx();
Promise promise = Promise.promise();
vertx.setTimer(1000, id -> {
if (System.currentTimeMillis() % 2L == 0L) {
promise.complete(good);
} else {
promise.fail(new Exception("Well"))
}
});
Future<String> future = promise.future();
future.recover(err -> Future.succeededFuture("Fail, but return that we acknowledged it failed"))
.map(String::toUpperCase)
.flatMap(str -> {
Promise next = Promise.promise();
vertx.setTimer(500, id -> next.complete("chain->" + str));
return next.future();
})
.onSuccess(System.out::println);In this simple example we have the following steps:
In the beginning, we create the Promise, start async operation setTimer that will run after 1 second
After that, we get Future from that Promise.
If the promise is finished in error, we try to recover by using Future#recover functionality
After we do some sync operation using map operator
Then we chain our future with another future using flatMap
And in the end, handle the final result in onSuccess.
As we can see this kind of coding style enables us to write more concise and clearer code, and of course, combine different async operations.
