Skip to content

Instantly share code, notes, and snippets.

@dklotz
Created March 22, 2017 21:14
Show Gist options
  • Save dklotz/083b49e23266cda392c92c8ee5e0377a to your computer and use it in GitHub Desktop.
Save dklotz/083b49e23266cda392c92c8ee5e0377a to your computer and use it in GitHub Desktop.
Trying to reproduce a problem with interceptors in Vert.x
package com.fileee.experiments.vertx;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.eventbus.EventBus;
import io.vertx.core.eventbus.Message;
import io.vertx.spi.cluster.hazelcast.HazelcastClusterManager;
public class InterceptorReproducer {
private static void demo(Vertx vertx) {
EventBus eventBus = vertx.eventBus();
eventBus.addInterceptor(sendContext -> {
Message message = sendContext.message();
System.out.println("Message intercepted:\n address: " + message.address() + "\n body: " + message.body() + "\n headers: " + message.headers());
sendContext.next();
});
eventBus.consumer("foo", message -> System.out.println("Consumer received: " + message.body()));
eventBus.publish("foo", "awesome!", new DeliveryOptions().addHeader("someHeader", "someValue"));
}
public static void main(String[] args) throws Exception {
boolean clustered = false;
if (clustered) {
Vertx.clusteredVertx(new VertxOptions().setClusterManager(new HazelcastClusterManager()),
result -> demo(result.result())
);
}
else {
demo(Vertx.vertx());
}
Thread.sleep(10000);
System.exit(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment