通过向build.gradle添加以下依赖项,我已经将vert.x添加到了Spring Boot应用程序中:
compile "io.vertx:vertx-core:3.8.1"
compile "io.vertx:vertx-lang-groovy:3.8.1"我想使用vert.xjvm在单个EventBus应用程序中实现反应式代码(没有Verticle)。
我已经验证了出站拦截器和SharedData是否正常工作。但是,没有任何入站拦截器或使用者被调用的迹象。
我怀疑我在配置vert.x时忽略了什么,或者在Spring Boot中嵌入vert.x以某种方式阻止了入站消息的接收。
Vertx vertx = Vertx.vertx();
vertx.eventBus().addInboundInterceptor(msg -> {
log.debug("abc inbound "+msg);
});
vertx.eventBus().addOutboundInterceptor(msg -> {
log.debug("abc outbound "+msg);
});
vertx.eventBus().<String>consumer("abc", (Message<String> msg) -> {
log.debug("abc handler");
});
vertx.eventBus().<String>localConsumer("localabc", (Message<String> msg) -> {
log.debug("local abc handler");
});
vertx.eventBus().consumer("abc", msg -> {
log.debug("abc handler 2");
});
vertx.eventBus().localConsumer("localabc", msg -> {
log.debug("local abc handler 2");
});
MessageConsumer<String> consumer1 = vertx.eventBus().consumer("abc");
consumer1.handler(msg -> {
log.debug("abc handler 3");
});
MessageConsumer<String> consumer2 = vertx.eventBus().localConsumer("localabc");
consumer2.handler(msg -> {
log.debug("local abc handler 3");
});
LocalMap<String, String> localMap = vertx.sharedData().getLocalMap("abc");
localMap.put("abc", "abc map");
vertx.eventBus().publish("abc", "test", new DeliveryOptions().setLocalOnly(true));
vertx.eventBus().publish("localabc", "localtest", new DeliveryOptions().setLocalOnly(true));
//LocalMap<String, String> localMap = vertx.sharedData().getLocalMap("abc");
log.debug("abc map contains "+localMap.get("abc"));以下是输出。没有任何类型的错误。
abc outbound io.vertx.core.eventbus.impl.EventBusImpl$OutboundDeliveryContext@3bab9a17
abc outbound io.vertx.core.eventbus.impl.EventBusImpl$OutboundDeliveryContext@54887f7e
abc map contains abc map发布于 2019-10-08 05:08:25
您正在没有使用next()的情况下使用outboundInterceptor
所以它的作用就像一个过滤器。它会捕获你的所有消息,并且永远不会将它们转发给消费者。
您可以只使用:
vertx.eventBus().addOutboundInterceptor(msg -> {
log.debug("abc outbound "+msg);
msg.next();
});https://stackoverflow.com/questions/58264485
复制相似问题