octo-rpc
octo-rpc copied to clipboard
Fix the DoradoHttpCheckHandler response
修复 Dorado HTTP 响应问题
背景
在测试 Dorado HTTP 响应时,发现结果与预期不符。在同一进程中同时初始化 Dorado 的 Invoker 和 Provider,~/service.info 接口启动后可能会返回 “PROVIDER not support service invoke”。
问题原因
Dorado 的 HttpServer 初始化异常。原因是 ServiceBootstrap.initHttpServer()
仅支持初始化一种 Rpc 角色。
public synchronized static void initHttpServer(RpcRole role) {
// 默认启动 http服务,作用于 服务自检
HttpServerFactory httpServerFactory = ExtensionLoader.getExtension(HttpServerFactory.class);
if (httpServer == null) {
httpServer = httpServerFactory.buildServer(role);
}
}
修复方案
如果 httpServer 已经初始化完成,那么重新设置 HttpServer.httpHandler.role 的字段值,以解决 HttpServer 仅支持初始化一种 Rpc 角色问题。
public synchronized static void initHttpServer(RpcRole role) {
// 默认启动 http服务,作用于 服务自检
HttpServerFactory httpServerFactory = ExtensionLoader.getExtension(HttpServerFactory.class);
if (httpServer == null) {
httpServer = httpServerFactory.buildServer(role);
} else if (httpServer.getHttpHandler() != null) {
HttpHandler httpHandler = httpServer.getHttpHandler();
RpcRole rpcRole = httpHandler.getRole();
if (rpcRole != null && rpcRole != role) {
rpcRole = RpcRole.MULTIROLE;
} else {
rpcRole = role;
}
httpHandler.setRole(rpcRole);
}
}