Created
March 22, 2017 21:14
-
-
Save dklotz/083b49e23266cda392c92c8ee5e0377a to your computer and use it in GitHub Desktop.
Trying to reproduce a problem with interceptors in Vert.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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