十三:Dubbo负载均衡(六)Directory执行流程

发起一个Consumer端的Rpc接口调用执行流程:

  1. org.apache.dubbo.rpc.proxy.InvokerInvocationHandler#invoke
  2. org.apache.dubbo.registry.client.migration.MigrationInvoker#invoke
  3. org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker#invoke
  4. org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster.ClusterFilterInvoker#invoke //开始过滤器链的执行
  5. org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder.FilterChainNode#invoke
  6. org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter#invoke
  7. org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder.FilterChainNode#invoke
  8. org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter#invoke
  9. org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker#invoke
  10. org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker#doInvoke
  11. org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker#invokeWithContext
  12. org.apache.dubbo.rpc.listener.ListenerInvokerWrapper#invoke
  13. org.apache.dubbo.rpc.protocol.AbstractInvoker#invoke
  14. org.apache.dubbo.rpc.protocol.dubbo.DubboInvoker#doInvoke

我们看下第9步的代码

	//org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker#invoke
    @Override
    public Result invoke(final Invocation invocation) throws RpcException {
        checkWhetherDestroyed();
        //获取invokers 集合
        List<Invoker<T>> invokers = list(invocation);
        LoadBalance loadbalance = initLoadBalance(invokers, invocation);
        RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
        return doInvoke(invocation, invokers, loadbalance);
    }
    protected List<Invoker<T>> list(Invocation invocation) throws RpcException {
        //我们进入list方法
        return getDirectory().list(invocation);
    }
	//org.apache.dubbo.rpc.cluster.directory.AbstractDirectory#list
    @Override
    public List<Invoker<T>> list(Invocation invocation) throws RpcException {
        if (destroyed) {
            throw new RpcException("Directory already destroyed .url: " + getUrl());
        }

        return doList(invocation);
    }
   	
    //org.apache.dubbo.registry.integration.RegistryDirectory#doList
    @Override
    public List<Invoker<T>> 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<Invoker<T>> invokers = null;
        try {
            // Get invokers from cache, only runtime routers will be executed.
            //通过此方法获取匹配的invoker集合
            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;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值