vert.xvertx-eventbus

How to list all consumers that are listening to an address on a vertex event bus?


I have a vert.x program. I am creating a message consumer and attach it to listen on an address on the vertx event bus . later in the program I am unregistering that consumer . How do I know if the consumer is unregistered successfully ?

following code snippet shows how i register a consumer on an address on vertex event bus

MessageConsumer<JsonObject> consumer = vertx.eventBus().consumer("my_channel", eventHandler)

later after sometime i am unregistering the consumer

consumer.unregister( res -> {
  if(res.succeeded()) { System.out.println("consumer deregistered")}
});

so my question is suppose i have reference to an vertx event bus vert.eventBus() object how can i verify it if there any consumers on it ?


Solution

  • As for the first question, you can safely assume consumer is unregistered successfully when res.succeeded() returns true inside unregister handler (as per your example).

    For the second part, afaik the event bus does not maintain the list of consumers registered to it, you have to maintain it yourself. The goal would be to have a map or some other collection where you store references for consumers when you register them with .consumer(...) method and remove them after unregister handler returns succeeded.

    I think this would be the issue you are referring to (with the advice by the lead architect of vertx): https://groups.google.com/g/vertx/c/d70YlHLL7KU?pli=1