[apache/dubbo]修改Provider提交到注册中心的ip和port,Consumer调用接口报 Not found exported service:

2023-12-15 6 views
0
Environment
  • Dubbo version: 2.6.0
  • Operating System version: Centos7
  • Java version: 1.8
Steps to reproduce this issue
  1. Provider添加环境变量DUBBO_IP_TO_REGISTRY=192.168.1.1和DUBBO_PORT_TO_REGISTRY=8080,启动后,注册到zk的信息变成了192.168.1.1:8080
  2. 启动Consumer
  3. 调用接口

Pls. provide [GitHub address] to reproduce this issue.

Expected Behavior

Consumer能正常调用Provider接口

Actual Behavior

调用异常:Not found exported service: xxx:20880 in xxxx , may be version or group mismatch , channel: consumer: ....

回答

0

经过解读源码,我的解决方案是修改 DubboProtocol.getInvoker

//--begin--//add by lgfei  
我添加的代码
 //--end--//add by lgfei

具体代码位置

    Invoker<?> getInvoker(Channel channel, Invocation inv) throws RemotingException {
        boolean isCallBackServiceInvoke = false;
        boolean isStubServiceInvoke = false;
        int port = channel.getLocalAddress().getPort();
        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();
        }
        //--begin--//add by lgfei
        String dubboPortToRegistry = ConfigUtils.getSystemProperty(Constants.DUBBO_PORT_TO_REGISTRY);
        if(StringUtils.isNotEmpty(dubboPortToRegistry)) {
            port = Integer.valueOf(dubboPortToRegistry);
        }
        //--end--//add by lgfei
        //后面源码省略.....
    }
9

我部署到k8s,注册到zookeeper的地址是 nodeIp:nodePort,socket绑定的 podIp:20880 我通过协议扩展的方式修复了,想确认一下这是不是一个bug,还是说有其他的配置可以规避这个问题

9

这个 DUBBO_PORT_TO_REGISTRY 配置的场景主要是存在 nat 的场景,有端口映射

5

如果是为了直接修改 PORT 可以直接指定 DUBBO_PROTOCOL_PROT=xxx,DUBBO_PORT_TO_REGISTRY 本身有一定的属性就是为了注册端口和发布端口不一样的场景的