I'd like to write a catch all eventBus consumer. Is this possible?
eB = vertx.eventBus();
MessageConsumer<JsonObject> consumer = eB.consumer("*"); // What is catch all address ???
consumer.handler(message -> {
Log.info("Received: " + message.body().toString());
});
A Vert. x event-bus is a light-weight distributed messaging system which allows different parts of your application, or different applications and services to communicate with each in a loosely coupled way. An event-bus supports publish-subscribe messaging, point-to-point messaging and request-response messaging.
Event loop theads and worker threads The API call vertx. executeBlocking() registered two handlers. Vert. x will call the blockingCodeHandler() using a worker thread and the resultHandler() using an event loop thread.
As the headline on the Vert. x website (vertx.io) says, “Eclipse Vert. x is a toolkit for building reactive applications on the JVM.” It is event-driven, single-threaded, and non-blocking, which means you can handle many concurrent apps with a small number of threads.
Vert. x uses low level IO library Netty. The application framework includes these features: Polyglot.
A solution to your problem might be an interceptor.
vertx.eventBus().addInterceptor( message -> {
System.out.println("LOG: " + message.message().body().toString());
});
This handler will write every message that comes to the event-bus in vertx.
Reference is here: http://vertx.io/docs/apidocs/io/vertx/rxjava/core/eventbus/EventBus.html#addInterceptor-io.vertx.core.Handler-
Also, version of vertx-core that I'm using is 3.3.2, I think interceptor functionality is not available in older versions (e.g. 3.0.0).
Having looked through the Java
code, I don't think this is possible.
Vert.x
stores event bus consumers in a MultiMap
looking like:
AsyncMultiMap<String, ServerID>
where the String key
is the consumer address
.
And as you'd guess, Vert.x
just does a map.get(address)
to find out the relevant consumers.
Update after OP comment
While I think your use case is valid, I think you're going to have to roll something yourself.
As far as I can see, Vert.x doesn't store consumers of send
and publish
separately. It's all in one MultiMap
. So it would be inadvisable to try to register consumers for all events.
If someone does an eventBus.send()
, and Vert.x selects your auditing consumer, it will be the only consumer
receiving the event, and I'm going to guess that's not what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With