The question is published on by Tutorial Guruji team.
We started using vert.x few days ago. Reading the documentation (A gentle guide to asynchronous programming with Eclipse Vert.x for Java developer – https://vertx.io/docs/guide-for-java-devs/) i understood the verticle concept.
What i didn’t understand is the concept of “service” and “service proxy”:
“That’s the main purpose of service proxies. It lets you expose a service on the event bus, so, any other Vert.x component can consume it, as soon as they know the address on which the service is published.
A service is described with a Java interface containing methods following the async pattern. Under the hood, messages are sent on the event bus to invoke the service and get the response back. But for ease of use, it generates a proxy that you can invoke directly”
But, how a single service is linked to the verticle & event loop concepts?
Does it belongs to a separate standalone verticle and it has his separated event loop or it belongs to a particular verticle?
When and where should i register a service? Inside a verticle start method or simply in the main method?
The level of granularity is rather free but basically, a verticle can expose one or more services (singleton implementing interfaces with business purpose) with different ways (here’s three common way for example).
The eventbus is a native way to allow verticles to communicate between them asynchronously on the model of messages queues.
So a verticle can expose one or more services by listening to one or more eventbus’s channels (and reply on this channels) and can invoke other services exposed by some other verticles by sending messages on other channel on the event bus.
1) no need to write a
main method using vert.x (you can use the
io.vertx.core.Launcher inside a fat jar or the
vertx executable to run your main verticle).
2) you can launch all of you verticles as separate pids using the
io.vertx.core.Launcher class inside a fat jar or
vertx executable or you can launch multiple verticles inside a main verticle so they share the same event loop by default (but you can also declare a pool of workers and use “worker verticles” according to : https://vertx.io/docs/vertx-core/java/#worker_verticles ).