Ilya Gazman
Ilya Gazman

Reputation: 32221

Vert.x Proxy Service - handle routing on different machiens

I got a webserver with 2 endpoints that I want to handle on different machines. They are independent and when updating one I don't want to restart the other.

    Router router = Router.router(vertx);
    router.route("/api*").handler(BodyHandler.create());
    router.post("/api/end_point_1").handler(new Handler1());
    router.post("/api/end_point_2").handler(new Handler2());

How can I achieve this in Vert.x? I been reading about Vert.x Service Proxy But I am not quite sure how to apply it to Router.

Upvotes: 1

Views: 366

Answers (2)

Alexey Soshin
Alexey Soshin

Reputation: 17701

What you're looking for is called Vertx cluster.

Your handlers would look something like this:

router.post("/api/end_point_1").handler(req -> {
   // Extract data from request
   // Package it into an object

   // Send it over EventBus
   vertx.eventBus().send("event1", data);
});

Now create another verticle in a separate application, which should do:

vertx.eventBus().consumer("event1");
    consumer.handler(o -> {
        System.out.println("Got message" + o.body());           
    });

Now to run those separate Jars follow this guide: http://vertx.io/docs/vertx-hazelcast/java/

Upvotes: 1

tsegismont
tsegismont

Reputation: 9128

I would simply package the code as two different JARs and deploy them independently. Then a load-balancer/API gateway/reverse-proxy would send the traffic to the right servers depending on the request URI.

Upvotes: 0

Related Questions