-
Notifications
You must be signed in to change notification settings - Fork 26.5k
dubbo provider side can't find service when deployed in docker. #1289
Description
有些部署场景需要动态指定服务注册的地址,如docker bridge网络模式下要指定注册宿主机ip以实现外网通信。dubbo提供了两对启动阶段的系统属性,用于设置对外通信的ip、port地址
DUBBO_IP_TO_REGISTRY --- 注册到注册中心的ip地址
DUBBO_PORT_TO_REGISTRY --- 注册到注册中心的port端口
docker环境下对外服务的端口为DUBBO_PORT_TO_REGISTRY,但服务提供端在读取端口号时读取到的是本地端口号导致无法找到对应的服务。BUG信息如下:
Not found exported service: hbec.app.test.service.TestService:20881 in [hbec.app.test.service.TestService:31838]
问题代码如下:
DubboProtocol类
Invoker<?> getInvoker(Channel channel, Invocation inv) throws RemotingException {
boolean isCallBackServiceInvoke = false;
boolean isStubServiceInvoke = false;
int port = channel.getLocalAddress().getPort();//# 注:在docker环境下该端口取的是本地端口,非环境变量端口
String path = inv.getAttachments().get(Constants.PATH_KEY);
// if it's callback service on client side
isStubServiceInvoke = Boolean.TRUE.toString().equals(inv.getAttachments().get(Constants.STUB_EVENT_KEY));
if (isStubServiceInvoke) {
port = channel.getRemoteAddress().getPort();
}