Vert.x event bus consumer called twice

311 Views Asked by At

i wrote a simple code for communicate between a java server in vert.x and a browser client with the event bus library. The client send a message to the server through the event bus and the server call eventbus.consumer to read the message and reply to it. I notice something strange, idk why the consumer method is called twice, I aspect it call one. How can i solve this? Thanks. This is my code:

SERVER

 SockJSBridgeOptions options = new SockJSBridgeOptions().
      addInboundPermitted(new PermittedOptions().setAddressRegex("out"));

    sockJSHandler.bridge(options);

    router.route("/eventbus/*").handler(sockJSHandler);

    eventBus.<String>consumer("out", event -> {
      logger.info(event.body());
      event.reply("TEST");
    });

    vertx.createHttpServer().requestHandler(router).listen(serverPort, res -> {
      if (res.succeeded()) {
        startPromise.complete();
      } else {
        startPromise.fail(res.cause());
      }
    });

CLIENT

  var eb = new EventBus('http://localhost:8088/eventbus');
  eb.onopen = () => {    
    eb.send('out', {name: 'tim', age: 5817}, (e, m) => {
      console.log("TEST RESPONSE")
      console.log(JSON.stringify(m));
    });
   }

CONSOLE SERVER OUTPUT

apr 07, 2022 7:55:43 PM it.unibo.guessthesong.lobby.LobbyVerticle
INFO: {"name":"tim","age":5817}
apr 07, 2022 7:55:43 PM it.unibo.guessthesong.lobby.LobbyVerticle
INFO: {"name":"tim","age":5817}

CONSOLE CLIENT OUTPUT

TEST RESPONSE
{"type":"rec","address":"92888ada-fada-43ff-9677-9eeed95b44da","body":"TEST"}
TEST RESPONSE
{"type":"rec","address":"2ced1214-13cf-4ebf-b7d8-6773612097e7","body":"TEST"}
0

There are 0 best solutions below