vert.x : tons of rest verticles vs one rest verticle routing to classes with event bus

48 Views Asked by At

this is not a real problem which needs help... but a discussion about the approach. Suppose i have a Java web application developed using vert.x which expose many REST services.

Would you deploy n REST verticles, each one reachable on its port and exposing his API?

or

would you just deploy one REST verticle and redirect calls internally using the event-bus and WebAPI?

Please explain why and if there's some detailed documentation or analysis.

Thank you

It's just thinking about how to do things

2

There are 2 best solutions below

1
Asad Awadia On

would you just deploy one REST verticle and redirect calls internally using the event-bus and WebAPI?

N verticles deployed all serving an http server on the same port. Each rest service is mounted as a subrouter on its service specific path

0
Oliver Marienfeld On

Vert.x recommends to encapsulate services as Verticles and use the EventBus for communication.

This gives you a lightweight separation of your services and scalability options:

  • If you deploy the services on one JVM, sending messages over the EventBus is merely as lightweight as a method call.
  • If you deploy in a Vert.x cluster (see Hazelcast, Infinispan, Zookeeper etc.), you won't have to change anything in your application - except for the deployment itself. And sending messages will still be relatively lightweight.

Start with one place where you configure HTTP routing. If the application grows and the single router becomes too messy, you can still separate that into Sub-Routers.

It’s not easy to give good advice without knowing your application. Vert.x does not force you into anything, though. So, if you find another approach that’s working it will be fine.