【网关】Shenyu网关调用Dubbo报org.apache.dubbo.rpc.RpcException: No provider available from registry localhost

org.apache.dubbo.rpc.RpcException: No provider available from registry localhost:8848 for service shinagawa-dubbo/com.demo.goods.api.TestService:DEFAULT on consumer 192.168.127.1 use dubbo version 2.7.18, please check status of providers(disabled, not registered or in blacklist).\r\n\tat org.apache.dubbo.registry.integration.DynamicDirectory.doList(DynamicDirectory.java:169)\r\n\tSuppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: \r\nError has been observed at the following site(s):\r\n\t*__checkpoint ⇢ org.apache.shenyu.web.configuration.ErrorHandlerConfiguration$1 [DefaultWebFilterChain]\r\n\t*__checkpoint ⇢ org.apache.shenyu.web.filter.LocalDispatcherFilter [DefaultWebFilterChain]\r\n\t*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter

遇到的问题:

今天对接shenyu网关时发现,通过网关调用dubbo服务时报错:rg.apache.dubbo.rpc.RpcException: No provider available from registry localhost:8848 for service shinagawa-dubbo/com.demo.goods.api.TestService:DEFAULT on consumer 192.168.127.1 use dubbo version 2.7.18, please check status of providers(disabled, not registered or in blacklist

org.apache.dubbo.rpc.RpcException: No provider available from registry localhost:8848 for service shinagawa-dubbo/com.demo.goods.api.TestService:DEFAULT on consumer 192.168.127.1 use dubbo version 2.7.18, please check status of providers(disabled, not registered or in blacklist

搜索“No provider available”后,打上断点进去看看啥情况

查看Nacos和ShenyuAdmin后台都有注册信息,那就很奇怪了。跟踪源代码,有几个地方,我们搜索“No provider available”后,打上断点进去看看啥情况:

【网关】Shenyu网关调用Dubbo报org.apache.dubbo.rpc.RpcException: No provider available from registry localhost_第1张图片

 重启gateway,再调用一次,断点发现在:

org.apache.dubbo.registry.integration.DynamicDirectory

    @Override
    public List> doList(Invocation invocation) {
        if (forbidden) {
            // 1. No service provider 2. Service providers are disabled
            throw new RpcException(RpcException.FORBIDDEN_EXCEPTION, "No provider available from registry " +
                    getUrl().getAddress() + " for service " + getConsumerUrl().getServiceKey() + " on consumer " +
                    NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() +
                    ", please check status of providers(disabled, not registered or in blacklist).");
        }

        if (multiGroup) {
            return this.invokers == null ? Collections.emptyList() : this.invokers;
        }

        List> invokers = null;
        try {
            // Get invokers from cache, only runtime routers will be executed.
            invokers = routerChain.route(getConsumerUrl(), invocation);
        } catch (Throwable t) {
            logger.error("Failed to execute router: " + getUrl() + ", cause: " + t.getMessage(), t);
        }

        return invokers == null ? Collections.emptyList() : invokers;
    }

【网关】Shenyu网关调用Dubbo报org.apache.dubbo.rpc.RpcException: No provider available from registry localhost_第2张图片

 看来是forbidden是true了

继续搜索给forbidden赋值的地方,打上断点。重启再次调用链路看看

【网关】Shenyu网关调用Dubbo报org.apache.dubbo.rpc.RpcException: No provider available from registry localhost_第3张图片

重启网关后,发现在org.apache.dubbo.registry.integration.RegistryDirectory

invokerUrls.get(0).getProtocol() 注册上去是empty

【网关】Shenyu网关调用Dubbo报org.apache.dubbo.rpc.RpcException: No provider available from registry localhost_第4张图片

这时,在断点处往上看调用栈针,在org.apache.dubbo.registry.integration.RegistryDirectory

继续往上:org.apache.dubbo.registry.nacos.NacosRegistry

就是这个instances为null,查询可用服务为null

 for (String serviceName : serviceNames) {
                    List instances = namingService.getAllInstances(serviceName,
                            getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
                    NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances);
                    notifySubscriber(url, serviceName, listener, instances);
                }

你可能感兴趣的:(软件研发,dubbo)