vert.x - 在springboot项目的verticles之间使用eventBus进行通信时没有地址处理程序
问题描述
我使用 Springboot 开发了一个项目,并使用 Vertx 作为异步响应式工具包。我的 ServerVerticle,创建一个 httpServer,它接收来自 Angular 应用程序的 http 请求并通过 eventBus 向它发送消息。顺便说一句,收到消息的时间,ServerVerticle 将它发送到另一个有服务实例的 Verticle(用于连接到存储库)。我用邮递员对其进行了测试,并得到“没有地址处理程序”错误作为错误请求。
这是我的 ServerVerticle:
HttpServerResponse res = routingContext.response();
res.setChunked(true);
EventBus eventBus = vertx.eventBus();
eventBus.request(InstrumentsServiceVerticle.FETCH_INSTRUMENTS_ADDRESS, "", result -> {
if (result.succeeded()) {
res.setStatusCode(200).write((Buffer) result.result().body()).end();
} else {
res.setStatusCode(400).write(result.cause().toString()).end();
}
});
我的 instrumentVerticle 如下:
static final String FETCH_INSTRUMENTS_ADDRESS = "fetch.instruments.service";
// Reuse the Vert.x Mapper :)
private final ObjectMapper mapper = Json.mapper;
private final InstrumentService instrumentService;
public InstrumentsServiceVerticle(InstrumentService instrumentService) {
this.instrumentService = instrumentService;
}
private Handler<Message<String>> fetchInstrumentsHandler() {
return msg -> vertx.<String>executeBlocking(future -> {
try {
future.complete(mapper.writeValueAsString(instrumentService.getInstruments()));
} catch (JsonProcessingException e) {
logger.error("Failed to serialize result "+ InstrumentsServiceVerticle.class.getName());
future.fail(e);
}
},
result -> {
if (result.succeeded()) {
msg.reply(result.result());
} else {
msg.reply(result.cause().toString());
}
});
}
@Override
public void start() throws Exception {
super.start();
vertx.eventBus().<String>consumer(FETCH_INSTRUMENTS_ADDRESS).handler(fetchInstrumentsHandler());
}
我在 springbootApp 启动器中部署了两个 Verticle。
解决方案
推荐阅读
- r - gcp 实例上的开源闪亮服务器无法连接到云 sql
- python - 如何在 Python 中编写一个函数来调用另一个函数,同时只为某些参数赋值?
- django - 为什么 nginx 显示 servererror(500) 并且在日志文件中显示 failed (98: Address already in use)
- java - GLSL 错误意外 $end at token "
"和格式问题 - django - 我们可以在 django 中为三种不同类型的用户进行三种不同的身份验证,并且所有三种用户都会以不同的方式登录
- html - 为什么将标签索引添加到标签会导致它影响 chrome 中的 :focus 行为?
- wpf - GroupSizeDefinition 不适用于为功能区组定义的样式
- python - UnicodeDecodeError:“charmap”编解码器无法解码位置 73776 中的字节 0x81
- react-native - 当我单击 react-native 中的平面列表项时,如何在文本组件上设置值?
- java - 从单独的类定义和初始化数组