发起一个Consumer端的Rpc接口调用执行流程:
- org.apache.dubbo.rpc.proxy.InvokerInvocationHandler#invoke
- org.apache.dubbo.registry.client.migration.MigrationInvoker#invoke
- org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker#invoke
- org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster.ClusterFilterInvoker#invoke //开始过滤器链的执行
- org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder.FilterChainNode#invoke
- org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter#invoke
- org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder.FilterChainNode#invoke
- org.apache.dubbo.rpc.protocol.dubbo.filter.FutureFilter#invoke
- org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker#invoke
- org.apache.dubbo.rpc.cluster.support.FailoverClusterInvoker#doInvoke
- org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker#invokeWithContext
- org.apache.dubbo.rpc.listener.ListenerInvokerWrapper#invoke
- org.apache.dubbo.rpc.protocol.AbstractInvoker#invoke
- 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;
}