Hi, I am trying to intercept any messages sent through the event bus to add a cache for some petitions.
I am trying to add logic so that in some cases it returns a cached result without really sending the message or allow the message to be sent if the result is not cached.
I am trying by using interceptors but i can't find a way to stop the message propagation to the bus (if i dont include the event.next(); the process just gets stuck waiting for the next interceptor to execute, which will never happen).
This is how I am trying to implement this:
Handler<DeliveryContext<K>> cacheInterceptor = new Handler<DeliveryContext<K>> () {
@Override
public void handle(DeliveryContext<K> event) {
K body = event.message().body();
Object cachedResponse = retrievefromCache(extractId(body));
if (cachedResponse != null) {
event.message().reply(cachedResponse);
//ADD LOGIC TO STOP EVENT PROPAGATION
} else {
event.next();
}
}
};
this.vertx.eventBus().addOutboundInterceptor(cacheInterceptor);
The code would be executed on the verticle initialization so that it intercepts all future calls to the event bus.
Does anyone know any way to do this or maybe another approach for what i am trying to achieve?