Publish / subscribe messaging
The event bus supports publishing messages.
Messages are published to an address. Publishing means delivering the message to all handlers that are registered at that address.
public void start() {
MessageConsumer<String> consumer = vertx.eventBus().consumer("MYADDRESS");
consumer.handler(message -> System.out.println("(1) received a message"));
consumer.handler(message -> System.out.println("(2) received a message"));
consumer.handler(message -> System.out.println("(3) received a message"));
}--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/a483ed8f-072f-4c97-be51-0eb7bd7ca3be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I believe if your create different consumer objects per handler that should suffice.
On Thu, Oct 27, 2016 at 5:21 AM, <boro...@gmail.com> wrote:
Hello,I'm trying to figure out how to register multiple handlers for a single Verticle address?According to the documentation:Publish / subscribe messaging
The event bus supports publishing messages.
Messages are published to an address. Publishing means delivering the message to all handlers that are registered at that address.I tried the following, but when I call publish from another Verticle the last handler (3) is always executed.public void start() {
MessageConsumer<String> consumer = vertx.eventBus().consumer("MYADDRESS");
consumer.handler(message -> System.out.println("(1) received a message"));
consumer.handler(message -> System.out.println("(2) received a message"));
consumer.handler(message -> System.out.println("(3) received a message"));
}
I understand that each handler I set below is overriding the previous one, but I just can't find and example online of adding multiple handlers. I'm sure I'm doing something fundamentally wrong, just need an example please.Thanks,p.s. I'm running vert.x 3.3.3
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/cf31babb-9eae-42f9-80f3-ae7463867c5d%40googlegroups.com.