I'm having my first contact with Vertx's EventBus and I realized there are two ways to submit a message. Used the send or publish method. I ask: What is the practical difference between using these two methods and in what scenario do they use each one?
A Vert. x event-bus is a light-weight distributed messaging system which allows different parts of your application, or different applications and services to communicate with each in a loosely coupled way. An event-bus supports publish-subscribe messaging, point-to-point messaging and request-response messaging.
The whole purpose of the event loop is to react to events which are delivered to the event loop by the operating system. Event loop processes those events by executing handlers. To explain how the event loop operates, let's imagine a typical HTTP server application serving multiple client connections at the same time.
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. @FunctionalInterface public interface Handler<E> A generic event handler. This interface is used heavily throughout Vert. x as a handler for all types of asynchronous occurrences.
You can deploy a verticle using one of the deployVerticle method, specifying a verticle name or you can pass in a verticle instance you have already created yourself. Deploying Verticle instances is Java only. Verticle myVerticle = new MyVerticle(); vertx. deployVerticle(myVerticle);
Both send
and publish
are used to send a message to an event bus address. However there are some differences between the two.
By using publish
:
By using send
:
In practical usage, publish
is quite useful to inform that an event has occured, whereas send
is quite handy for asking a treatment where the response matters.
Conceptually, publish
uses the publish/subscribe pattern whereas send
uses the request/response pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With