Skip to content

dubbo provider side can't find service when deployed in docker. #1289

Closed

Description

@skiof007

有些部署场景需要动态指定服务注册的地址,如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();
}

Activity

  1. changed the title [-]dubbo在docker环境下找不到服务问题[/-] [+]dubbo provider side can't find service when deployed in docker.[/+] on Jan 29, 2018
  2. chickenlj commented on Jan 29, 2018

    @chickenlj
    Contributor

    DUBBO_IP_TO_REGISTRY and DUBBO_PORT_TO_REGISTRY don't affect the ip and port your provider bind to. If you only specify ip and port for registry and use different ip and port for binding, your network should have a mechanism to map registry ip/port with bind ip/port automatically. Like Port Mapping docker provides.

  3. skiof007 commented on Jan 30, 2018

    @skiof007
    Author

    感谢你的回复,我们已经在docker中做了端口映射,并且我们通过命令
    telnet 30.5.97.6 31838
    ls
    invoke hbec.app.test.service.TestService.test()

    是可以正常调通并且我们在zookeeper中也是可以发现31838注册的provider服务,但我们通过consumer去调用provider端时,provider端会报如下错误:
    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();

        //下面代码为我们自己添加的代码
        String portToRegistryStr = ConfigUtils.getSystemProperty(Constants.DUBBO_PORT_TO_REGISTRY);
        if(null!=portToRegistryStr){
        	port=Integer.parseInt(portToRegistryStr);//取环境变量设置的端口
        }
    

    经重新编译打包源码后测试调用成功。

    docker端口映射代码如下:
    "ports": [
    {
    "name": "dubbo",
    "protocol": "TCP",
    "port": 20881,
    "targetPort": 20881,
    "nodePort": 31838
    }
    ]

  4. added
    type/bug
    on Jan 30, 2018
  5. added this to the 2.5.10 milestone on Feb 5, 2018
  6. added a commit that references this issue on Feb 5, 2018
    108fe0f
  7. added 3 commits that reference this issue on Feb 26, 2018
    0d7dfaa
    125e6a1
    a3b8d73
  8. added a commit that references this issue on Sep 9, 2019
    ed77cdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions