1
votes

I am working on a system where I send messages to a server using web sockets. For this, I use vertx (without Rx) web sockets client with multiple verticles and the messages are stored in an internal queue. I wish to dequeue from the messaging queue and submit to a verticle is has the least load. To identify the verticle with least load I plan to use a ratio of number messages ack received to number messages sent. I understand vertx web sockets are async in nature. But is there a provision to use any of the provided handlers to parse the response which indicates the message had reached the server.


Please note: The communication is one way ie only from client to server and server is not on vertx, it uses plain netty Thanks in advance.
1

1 Answers

3
votes

You can use a combination of SharedData and regular handlers:

this.vertx.createHttpServer().websocketHandler(ws -> {
  ws.handler(data -> {
    this.vertx.sharedData().getCounter(this.deploymentID(), (c) -> {
      c.result().incrementAndGet((dummy) -> {});
    });
  });
});

This will increment an atomic counter for specific verticle each time a new WebSocket request comes in.

Now you can get all deployment IDs using vertx.deploymentIDs()

What's left is to iterate over those, gather the counters, then get the minimal one.