1

I have a question concerning the Vertx Eventbus and how to use it properly. There are at least two options of using the EventBus in Vertx:

  1. I use the Eventbus methods provided by Vertx to call functions residing on another Verticle. The upside here is that I can use Codecs to pass parameters over the Eventbus. If i only want to use it locally, i can just pass the reference. The downside here is that I need to provide a String to define which function I want to call. Looking at developer speed, this is very bad, because now I have to search for Strings in the code base to find the functions that I call.

  2. I use Vertx Service Proxy. This is quite handy as it generates proxies for the Eventbus on compile time. This allows me as a developer to follow the functions I am calling across Verticles and I do not have to deal with the Eventbus API at all. However it has some important drawbacks as well: Now the startup time takes longer and the Service Proxy is converting all function properties to and from Json. This can be very bad for application performance.

My question: What is the best way to use the Eventbus? Am I missing something that can help me with the drawbacks of option two? Are there alternatives that I dont see yet?

Thanks

1 Answers1

0

the main way is, as you discovered, to use string addresses. there are many reasons why this is done specially that event bus could potentially stretch over network and extend to other JVMs, machines and even non-JVM environments, so they should all be able to handle messages.

as you mentioned, for passing trivial POJOs you need a codec and most codecs differentiate between being called locally, and therefore passing a reference and being called for over network conversion. So you don't need to worry here. An easy way for not writing a codec for every kind of class you define is using @DataObject and letting code generation take care of it. This way you just send and receive POJOs and the rest is done automatically. This was not using serialization at least until some time ago (see here).

as for Service Proxy, the current implementation always serializes all the parameters but this issue was already raised a long time ago. But this is the price you are paying for type safety (at least to some extend).

to sum up, there is no best way to use eventbus, it all depends on what you are looking for. You could define constant strings for addresses and use them so that you are not looking for strings all over the code or for a type safe variation you could use service proxy.

mohamnag
  • 2,709
  • 5
  • 27
  • 40
  • Thanks for the response. Maybe I misunderstood but the Service Proxy serialises all function parameters and all return values within the Futures even when they are DataObjects, right? In this case I pay a really high performance price. – Maximilian Deichmann Nov 17 '20 at 18:07
  • you are right, I had the wrong impression, but looking at [this](https://vertx.io/docs/vertx-service-proxy/java/#_convention_for_invoking_services_over_the_event_bus_without_proxies) I found out that you are right and it always de/serializes – mohamnag Nov 18 '20 at 08:32
  • btw, I'm not really sure if thats a "really high performance price". if you use vertx codegen to create de/serializers, they are actually very very fast. don't use Jackson or similar solution. I have experience with multiple layers of services all done with vertx and they all do such de/serializations internally and the whole roundtrip takes less than 50ms per request. – mohamnag Nov 18 '20 at 08:34