我们可以轻松用@DubboReference调用dubbo注册中心里面的服务,其实Dubbo为背地里为我们做了很多事情,下图为调用栈
org.apache.dubbo.config.ReferenceConfig#createInvokerForRemote,
根据
protocolSPI通过注册服务url registry://128.30.14.249:8848/org.apache.dubbo.registry.RegistryService返回interfaceClass的invoker,invoker里面有个重要的属性directory,它的invokers属性记录了这个interface在远程的所有服务实例(ip/port)。
org.apache.dubbo.common.bytecode.Proxy#getProxy
最后由org.apache.dubbo.common.bytecode.Proxy#getProxy生成执行代理
org.apache.dubbo.registry.client.migration.MigrationInvoker#invoke根据负载平衡策略
return this.step == MigrationStep.APPLICATION_FIRST && ThreadLocalRandom.current().nextDouble(100.0D) > (double)this.promotion ? this.invoker.invoke(invocation) : this.currentAvailableInvoker.invoke(invocation);
最终由org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder.FilterChainNode#invoke ->org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter#invoke实现远程方法调用。
因为FilterChainNode随机性而且没有属性记载最后一次用的是哪个节点,所以无法获取当前引用的远程ip/port,invoker的directory里面的invokers获取这个引用可用的远程实例列表



