[2.7.15] dubbo自定义dispatcher,consumer无法找到provider

camsedfj  于 2022-10-21  发布在  其他
关注(0)|答案(1)|浏览(243)
  • Dubbo version: 2.7.15(2.7.7测试也存在)
  • nacos version: 2.0.2
  • Operating System version: macos12、centos7
  • Java version: 1.8

复现

nacos:重启nacos或者使用新的一个ip启动provider应用

dubbo:

首先新建一个自定义Dispatcher

public class TestDispatcher implements Dispatcher {
    public static final String NAME = "test";
    @Override
    public ChannelHandler dispatch(ChannelHandler handler, URL url) {
        return new MessageOnlyChannelHandler(handler, url);
    }
}

同时在META-INFO.dubbo中也创建对应文件

在配置中指定:

dubbo.protocol.dispatcher=test

启动服务后,nacos注册成功,可以看到dispatcher等信息都是成功注册的,同时consumer在nacos上也可以看到

{
	"side": "provider",
	"service.name": "ServiceBean:/xxx.xxx.demo.serivce.SayService",
	"methods": "sayHelloByName",
	"release": "2.7.15",
	"deprecated": "false",
	"dubbo": "2.0.2",
	"threads": "5",
	"pid": "77518",
	"interface": "xxx.xxx.demo.serivce.SayService",
	"threadpool": "fixed",
	"generic": "false",
	"corethreads": "5",
	"path": "xxx.xxx.demo.serivce.SayService",
	"protocol": "dubbo",
	"metadata-type": "remote",
	"application": "provider-service",
	"dynamic": "true",
	"category": "providers",
	"dispatcher": "test",
	"anyhost": "true",
	"threadname": "default-thread",
	"timestamp": "1643015362814"
}

但是调用服务会失败:

Failed to invoke the method sayHelloByName in the service xxx.xxx.demo.serivce.SayService. No provider available for the service xxx.xxx.demo.serivce.SayService from registry 127.0.0.1:8848 on the consumer 10.179.116.54 using the dubbo version 2.7.15. Please check if the providers have been started and registered.

如何调用成功

在配置中修改dispatcher为message,启动服务注册成功后,再将dispatcher改为test,重启服务,consumer便可以成功调用

dubbo.protocol.dispatcher=message

但是线上k8s等服务ip可能会改变,不可能使用改dispatcher重启等方法让consumer调用

暂时的解决办法

将自定义的dispatcher的name定义为dubbo已有的,比如message,覆写该dispatcher,便可以直接调用成功

zujrkrfu

zujrkrfu1#

Check whether the request to establish a connection is initiated when the call fails, and whether the address of the established connection is correct.
In theory, the Dispatcher has nothing to do with whether there are available nodes.

相关问题