Dubbo客户端订阅流程

流程图

DubboReference标签引用

get

org.apache.dubbo.config.ReferenceConfig#get

//引用提供方的核心方法
@Override
@Transient
public T get(boolean check) {
     //判断是否被销毁
    if (destroyed) {
        throw new IllegalStateException("The invoker of ReferenceConfig(" + url + ") has already destroyed!");
    }

    //如果ref对象为空就初始化一个
    //说明引用提供方的每个接口都有着与之对应的一个ref对象
    if (ref == null) {
        //ScopeModel 领域模型
        if (getScopeModel().isLifeCycleManagedExternally()) {
            // prepare model for reference
            getScopeModel().getDeployer().prepare();
        } else {
            // ensure start module, compatible with old api usage
            getScopeModel().getDeployer().start();
        }

        //重点 ,如果没有就 初始化 ref 对象
        init(check);
    }

    return ref;
}

Init

//org.apache.dubbo.config.ReferenceConfig#init(boolean)
// 核心逻辑是创建代理 createProxy
protected void init(boolean check) {
    lock.lock();
    try {

        try {
            // init serviceMetadata
            //初始化服务元数据
            initServiceMetadata(consumer);

            serviceMetadata.setServiceType(getServiceInterfaceClass());
            // TODO, uncomment this line once service key is unified
            serviceMetadata.generateServiceKey();

            Map<String, String> referenceParameters = appendConfig();

            ModuleServiceRepository repository = getScopeModel().getServiceRepository();
            ServiceDescriptor serviceDescriptor;
            if (CommonConstants.NATIVE_STUB.equals(getProxy())) {
                serviceDescriptor = StubSuppliers.getServiceDescriptor(interfaceName);
                repository.registerService(serviceDescriptor);
                setInterface(serviceDescriptor.getInterfaceName());
            } else {
                serviceDescriptor = repository.registerService(interfaceClass);
            }
            //生成消费模型
            consumerModel = new ConsumerModel(
                    serviceMetadata.getServiceKey(),
                    proxy,
                    serviceDescriptor,
                    getScopeModel(),
                    serviceMetadata,
                    createAsyncMethodInfo(),
                    interfaceClassLoader);

            // Compatible with dependencies on ServiceModel#getReferenceConfig() , and will be removed in a future
            // version.
            consumerModel.setConfig(this);

            repository.registerConsumer(consumerModel);

            serviceMetadata.getAttachments().putAll(referenceParameters);

            //根据引用参数创建代理对象
            //设置了 @DubboReferenc注解的配置,最终会在综合为一个Map对象
//而这个所谓的Map对象其实就是referencParameters这个引用参数对象
//根据引用参数创建代理对象
            ref = createProxy(referenceParameters);

            serviceMetadata.setTarget(ref);
            serviceMetadata.addAttribute(PROXY_CLASS_REF, ref);

            consumerModel.setDestroyRunner(getDestroyRunner());
            consumerModel.setProxyObject(ref);
            consumerModel.initMethodModels();

            if (check) {
                checkInvokerAvailable(0);
            }
        } catch (Throwable t) {
            logAndCleanup(t);

            throw t;
        }
        initialized = true;
    } finally {
        lock.unlock();
    }
}

createProxy

//org.apache.dubbo.config.ReferenceConfig#createProxy
//创建代理对象的核心逻辑  : inJvm 引用+远程引用+生成代理对象
private T createProxy(Map<String, String> referenceParameters) {
    urls.clear();

    meshModeHandleUrl(referenceParameters);

// 是否配置了客户端用户点点直连的Url  @DubboReferenc(url="tri://192.168.1.2")
    if (StringUtils.isNotEmpty(url)) {
        // user specified URL, could be peer-to-peer address, or register center's address.
//如果消费者端配置了url属性,那么dubbo会认为该rul是一个点对点地址,或者是一个注册中心的地址
        parseUrl(referenceParameters);
    } else {
        // if protocols not in jvm checkRegistry
         dubbo走从注册中心拉取服务提供者url那套逻辑
        aggregateUrlFromRegistry(referenceParameters);
    }
    createInvoker();

    //consumer:
    //consumer://192.168.1.126/cn.uid.service.UidService?application=uap-sys-setting-application&background=false&check=false&check.serializable=false&dubbo=2.0.2&executor-management-mode=isolation&file-cache=true&interface=cn.uid.service.UidService&methods=getBatchIds,getDataCenterId,getNextId,getWorkerId&mse.project.name=j1h07oev3e@f616b8f0b37130c&opensergo.io/canary=&pid=93470&qos.enable=true&register-mode=instance&register.ip=192.168.1.126&release=3.3.0-beta.4&retries=0&serialize.check.status=DISABLE&side=consumer&sticky=false&timeout=3000&timestamp=1722499887439&unloadClusterRelated=false
    URL consumerUrl = new ServiceConfigURL(
            CONSUMER_PROTOCOL,
            referenceParameters.get(REGISTER_IP_KEY),
            0,
            referenceParameters.get(INTERFACE_KEY),
            referenceParameters);
    consumerUrl = consumerUrl.setScopeModel(getScopeModel());
    consumerUrl = consumerUrl.setServiceModel(consumerModel);
    MetadataUtils.publishServiceDefinition(consumerUrl, consumerModel.getServiceModel(), getApplicationModel());

    // create service proxy
    return (T) proxyFactory.getProxy(invoker, ProtocolUtils.isGeneric(generic));
}

/**
 * Get URLs from the registry and aggregate them.
 */
private void aggregateUrlFromRegistry(Map<String, String> referenceParameters) {
    checkRegistry();
    List<URL> us = ConfigValidationUtils.loadRegistries(this, false);
    if (CollectionUtils.isNotEmpty(us)) {
        for (URL u : us) {
            URL monitorUrl = ConfigValidationUtils.loadMonitor(this, u);
            if (monitorUrl != null) {
                u = u.putAttribute(MONITOR_KEY, monitorUrl);
            }
            u = u.setScopeModel(getScopeModel());
            u = u.setServiceModel(consumerModel);
            if (isInjvm() != null && isInjvm()) {
                u = u.addParameter(LOCAL_PROTOCOL, true);
            }
            urls.add(u.putAttribute(REFER_KEY, referenceParameters));
        }
    }
    //injvm://xxxxxxxxx 
    if (urls.isEmpty() && shouldJvmRefer(referenceParameters)) {
        URL injvmUrl = new URL(LOCAL_PROTOCOL, LOCALHOST_VALUE, 0, interfaceClass.getName())
                .addParameters(referenceParameters);
        injvmUrl = injvmUrl.setScopeModel(getScopeModel());
        injvmUrl = injvmUrl.setServiceModel(consumerModel);
        urls.add(injvmUrl.putAttribute(REFER_KEY, referenceParameters));
    }
    if (urls.isEmpty()) {
        throw new IllegalStateException("No such any registry to reference " + interfaceName + " on the consumer "
                + NetUtils.getLocalHost() + " use dubbo version "
                + Version.getVersion()
                + ", please config <dubbo:registry address=\"...\" /> to your spring config.");
    }
}

consumer://192.168.1.126/cn.uid.service.UidService?application=sys-setting-application&background=false&check=false&check.serializable=false&dubbo=2.0.2&executor-management-mode=isolation&file-cache=true&interface=cn.itbox.uap.uid.service.UidService&methods=getBatchIds,getDataCenterId,getNextId,getWorkerId&mse.project.name=j1h07oev3e@f616b8f0b37130c&opensergo.io/canary-huyanbing=huyanbing&pid=93470&qos.enable=true&register-mode=instance&register.ip=192.168.1.126&release=3.3.0-beta.4&retries=0&serialize.check.status=DISABLE&side=consumer&sticky=false&timeout=3000&timestamp=1722499887439&unloadClusterRelated=false

org.apache.dubbo.registry.integration.RegistryProtocol#refer

根据

@DubboReference

private UidService uidService;

生成 UidServiceDubboProxy 对象

MigrationInvoker{serviceKey=cn.uid.service.UidService, invoker=null, step=FORCE_APPLICATION}

createInvoker

//org.apache.dubbo.config.ReferenceConfig#createInvoker
private void createInvoker() {
// 如果urls 集合只有1个元素的话,则直接调用refer 进行远程引用
// 如果urls 的长度为1 ,说明只有一个服务提供者,则直接通过protocolSPI.refer创建一个Invoker实例
//如果这个服务提供者不是注册中心,则使用StaticDirectory对这个Invokder进行包装
//StaticDirectory是Dubbo框架中的一个类,用于将一组Invoker封装成一个目录,以便消费者调用
    if (urls.size() == 1) {
        URL curUrl = urls.get(0);
        //远程引用的核心代码
//这里根据urlAddress 内部的protocol属性作为key ,通过dubbo的SPI 机制寻找对应协议的实现类
//这里实际调用的DubbProtocol、TripleProtocol的refer方法,因为urlAddress的protocl值为Dubbo、tri
        invoker = protocolSPI.refer(interfaceClass, curUrl);
        // registry url, mesh-enable and unloadClusterRelated is true, not need Cluster.
        if (!UrlUtils.isRegistry(curUrl) && !curUrl.getParameter(UNLOAD_CLUSTER_RELATED, false)) {
        //如果这个curUrl不是注册协议的话  service-discovery-registry registry://  
        //那么就用集群扩展器包装起来
            List<Invoker<?>> invokers = new ArrayList<>();
            invokers.add(invoker);
            invoker = Cluster.getCluster(getScopeModel(), Cluster.DEFAULT)
                    .join(new StaticDirectory(curUrl, invokers), true);
        }
    } 
    // url 集合有多个地址的情况
    // 可能有注册中心地址,也可能有服务接口地址
    // 混合的情况
    else {
        List<Invoker<?>> invokers = new ArrayList<>();
        URL registryUrl = null;
        // 直接循环一个个远程引用
        for (URL url : urls) {
            // For multi-registry scenarios, it is not checked whether each referInvoker is available.
            // Because this invoker may become available later.
            // 循环体中单独针对一个url 进行远程引用
            invokers.add(protocolSPI.refer(interfaceClass, url));

            if (UrlUtils.isRegistry(url)) {
                // use last registry url
                //service-discovery-registry
                registryUrl = url;
            }
        }
        //循环完毕,若发现没有注册中心地址registry://
        //那就有可能就是 点对点直连的方式进行 点对点链接
        //于是 还是一样采用集群扩展包装起来
        if (registryUrl != null) {
            // registry url is available
            // for multi-subscription scenario, use 'zone-aware' policy by default
            对于多注册表场景,不检查每个referInvoker是否可用。
            //因为这个调用程序以后可能可用。
            String cluster = registryUrl.getParameter(CLUSTER_KEY, ZoneAwareCluster.NAME);
            // The invoker wrap sequence would be: ZoneAwareClusterInvoker(StaticDirectory) ->
            // FailoverClusterInvoker
            // (RegistryDirectory, routing happens here) -> Invoker
            invoker = Cluster.getCluster(registryUrl.getScopeModel(), cluster, false)
                    .join(new StaticDirectory(registryUrl, invokers), false);
        } else {
            // not a registry url, must be direct invoke.
            if (CollectionUtils.isEmpty(invokers)) {
                throw new IllegalArgumentException("invokers == null");
            }
            URL curUrl = invokers.get(0).getUrl();
            String cluster = curUrl.getParameter(CLUSTER_KEY, Cluster.DEFAULT);
            invoker =
                    Cluster.getCluster(getScopeModel(), cluster).join(new StaticDirectory(curUrl, invokers), true);
        }
    }
}

consumer://192.168.1.102/cn.uid.service.UidService?application=uap-demo-org-application&background=false&check=false&check.serializable=false&dubbo=2.0.2&executor-management-mode=isolation&file-cache=true&interface=cn.uid.service.UidService&methods=getBatchIds,getDataCenterId,getNextId,getWorkerId&pid=84690&qos.enable=true&register-mode=instance&register.ip=192.168.1.102&release=3.3.0&retries=0&serialize.check.status=DISABLE&side=consumer&sticky=false&timeout=10000&timestamp=1727592802768&unloadClusterRelated=false

调用链路为:

doRefer:591, RegistryProtocol (org.apache.dubbo.registry.integration)
refer:574, RegistryProtocol (org.apache.dubbo.registry.integration)
refer:83, ProtocolListenerWrapper (org.apache.dubbo.rpc.protocol)
refer:85, QosProtocolWrapper (org.apache.dubbo.qos.protocol)
refer:112, ProtocolSecurityWrapper (org.apache.dubbo.rpc.protocol)
refer:72, ProtocolFilterWrapper (org.apache.dubbo.rpc.cluster.filter)
refer:55, ProtocolSerializationWrapper (org.apache.dubbo.rpc.protocol)
refer:48, InvokerCountWrapper (org.apache.dubbo.rpc.protocol)
refer:-1, Protocol$Adaptive (org.apache.dubbo.rpc)
createInvoker:672, ReferenceConfig (org.apache.dubbo.config)
createProxy:502, ReferenceConfig (org.apache.dubbo.config)
init:383, ReferenceConfig (org.apache.dubbo.config)
get:244, ReferenceConfig (org.apache.dubbo.config)
get:140, SimpleReferenceCache (org.apache.dubbo.config.utils)
lambda$referServices$6:567, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
accept:-1, DefaultModuleDeployer$$Lambda/0x000000e001ac8690 (org.apache.dubbo.config.deploy)
forEach:4783, ConcurrentHashMap$ValuesView (java.util.concurrent)
referServices:539, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
startSync:186, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
start:159, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
onContextRefreshedEvent:167, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
onApplicationEvent:153, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
onApplicationEvent:52, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
doInvokeListener:176, SimpleApplicationEventMulticaster (org.springframework.context.event)
invokeListener:169, SimpleApplicationEventMulticaster (org.springframework.context.event)
multicastEvent:143, SimpleApplicationEventMulticaster (org.springframework.context.event)
publishEvent:413, AbstractApplicationContext (org.springframework.context.support)
publishEvent:370, AbstractApplicationContext (org.springframework.context.support)
finishRefresh:937, AbstractApplicationContext (org.springframework.context.support)
refresh:587, AbstractApplicationContext (org.springframework.context.support)
refresh:732, SpringApplication (org.springframework.boot)
refreshContext:434, SpringApplication (org.springframework.boot)
run:310, SpringApplication (org.springframework.boot)
run:150, SpringApplicationBuilder (org.springframework.boot.builder)
main:51, OrgDemoApplication (cn.itbox.uap.demo.org.application)

断点设置在

org.apache.dubbo.remoting.transport.netty4.NettyClient#doConnect()

https://www.163.com/dy/article/GB09B3KK05315U6Q.html

protocolSPI.refer

@SPI(value = "dubbo", scope = ExtensionScope.FRAMEWORK)
public interface Protocol {

    /**
     * Get default port when user doesn't config the port.
     *
     * @return default port
     */
    int getDefaultPort();

    /**
     * Export service for remote invocation: <br>
     * 1. Protocol should record request source address after receive a request:
     * RpcContext.getServerAttachment().setRemoteAddress();<br>
     * 2. export() must be idempotent, that is, there's no difference between invoking once and invoking twice when
     * export the same URL<br>
     * 3. Invoker instance is passed in by the framework, protocol needs not to care <br>
     *
     * @param <T>     Service type
     * @param invoker Service invoker
     * @return exporter reference for exported service, useful for unexport the service later
     * @throws RpcException thrown when error occurs during export the service, for example: port is occupied
     */
    @Adaptive
    <T> Exporter<T> export(Invoker<T> invoker) throws RpcException;

    /**
     * Refer a remote service: <br>
     * 1. When user calls `invoke()` method of `Invoker` object which's returned from `refer()` call, the protocol
     * needs to correspondingly execute `invoke()` method of `Invoker` object <br>
     * 2. It's protocol's responsibility to implement `Invoker` which's returned from `refer()`. Generally speaking,
     * protocol sends remote request in the `Invoker` implementation. <br>
     * 3. When there's check=false set in URL, the implementation must not throw exception but try to recover when
     * connection fails.
     *
     * @param <T>  Service type
     * @param type Service class
     * @param url  URL address for the remote service
     * @return invoker service's local proxy
     * @throws RpcException when there's any error while connecting to the service provider
     */
    @Adaptive
    <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException;

    /**
     * Destroy protocol: <br>
     * 1. Cancel all services this protocol exports and refers <br>
     * 2. Release all occupied resources, for example: connection, port, etc. <br>
     * 3. Protocol can continue to export and refer new service even after it's destroyed.
     */
    void destroy();

    /**
     * Get all servers serving this protocol
     *
     * @return
     */
    default List<ProtocolServer> getServers() {
        return Collections.emptyList();
    }
}

//org.apache.dubbo.rpc.protocol.AbstractProtocol#refer
//抽象类中有 refer方法,但是refer 中又调用了 protocolBindingRefer 抽象方法
@Override
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
    return protocolBindingRefer(type, url);
}


//org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol#protocolBindingRefer
//org.apache.dubbo.rpc.protocol.injvm.InjvmProtocol#protocolBindingRefer
//org.apache.dubbo.rpc.protocol.tri.TripleProtocol#protocolBindingRefer
//
@Deprecated
protected abstract <T> Invoker<T> protocolBindingRefer(Class<T> type, URL url) throws RpcException;




//org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol#protocolBindingRefer
//重写父类的 protocolBindingRefer方法,其实间接执行了 refer的逻辑
//直接创建一个 DubboInvoker 对象
@Override
public <T> Invoker<T> protocolBindingRefer(Class<T> serviceType, URL url) throws RpcException {
    checkDestroyed();
    optimizeSerialization(url);

    // create rpc invoker.
    DubboInvoker<T> invoker = new DubboInvoker<>(serviceType, url, getClients(url), invokers);
    invokers.add(invoker);

    return invoker;
}

实现类为:

RegistryProtocol#refer

//org.apache.dubbo.registry.integration.RegistryProtocol#refer
@Override
@SuppressWarnings("unchecked")
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
    url = getRegistryUrl(url);
    Registry registry = getRegistry(url);
    if (RegistryService.class.equals(type)) {
        return proxyFactory.getInvoker((T) registry, type, url);
    }

    // group="a,b" or group="*"
    Map<String, String> qs = (Map<String, String>) url.getAttribute(REFER_KEY);
    String group = qs.get(GROUP_KEY);
    if (StringUtils.isNotEmpty(group)) {
        if ((COMMA_SPLIT_PATTERN.split(group)).length > 1 || "*".equals(group)) {
            return doRefer(
                    Cluster.getCluster(url.getScopeModel(), MERGEABLE_CLUSTER_NAME), registry, type, url, qs);
        }
    }

    Cluster cluster = Cluster.getCluster(url.getScopeModel(), qs.get(CLUSTER_KEY));
    return doRefer(cluster, registry, type, url, qs);
}

注册

 
registry://localhost:8848/org.apache.dubbo.registry.RegistryService?REGISTRY_CLUSTER=default:itbox-nacos&application=sys-setting-application&check=false&check.serializable=false&dubbo=2.0.2&executor-management-mode=isolation&file-cache=true&&namespace=itbox-nacos&opensergo.io/canary-xxx=xxx&pid=94294&qos.enable=true&register=true&register-mode=instance&registry=nacos&release=3.3.0-beta.4&serialize.check.status=DISABLE&timestamp=1722501219429 


registry://localhost:8848/org.apache.dubbo.registry.RegistryService?REGISTRY_CLUSTER=default:itbox-nacos&access-key=LTAI5tRF5VG1KR6zvFGP9rzq&&application=demo-org-application&check=false&check.serializable=false&dubbo=2.0.2&executor-management-mode=isolation&file-cache=true&&namespace=dev-nacos&serialize.check.status=DISABLE&timestamp=1722512271413

1、远程引用的 urls 可以是注册中心地址,也可以是多个提供方点对点地址

2、urls集合的数量不管是一个还是多个,最终都是循环调用refer方法,然后累加refer 的所有结果,最终被集群扩展器包装成一个invoker

3、refer 的方法中将注册器、集群扩展器、接口等信息全部封装到了一个 doRefer方法中

APPLICATION_FIRST、FORCE_INTERFACE

接口级注册才会走

org.apache.dubbo.registry.client.migration.MigrationInvoker#migrateToForceInterfaceInvoker

org.apache.dubbo.registry.client.migration.MigrationInvoker#refreshInterfaceInvoker

invoker = registryProtocol.getInvoker(cluster, registry, type, url);

doCreateInvoker

org.apache.dubbo.registry.integration.RegistryProtocol#doCreateInvoker 

这里设置一个断点

//org.apache.dubbo.registry.integration.RegistryProtocol#doCreateInvoker
//回到了注册协议实现类的创建invoker方法
protected <T> ClusterInvoker<T> doCreateInvoker(
        DynamicDirectory<T> directory, Cluster cluster, Registry registry, Class<T> type) {
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    // all attributes of REFER_KEY
    // 构建写到注册中心的地址信息
    //之前在导出的方法中,提供者会把服务接口的地址信息写到注册中心上
    //dubbo 服务不管是提供者还是消费者,都要写到注册中心上
    //最终都会把自己的提供的服务接口信息,或者订阅的服务接口信息,写到注册中心上
    Map<String, String> parameters =
            new HashMap<>(directory.getConsumerUrl().getParameters());
    URL urlToRegistry = new ServiceConfigURL(
            parameters.get(PROTOCOL_KEY) == null ? CONSUMER : parameters.get(PROTOCOL_KEY),
            parameters.remove(REGISTER_IP_KEY),
            0,
            getPath(parameters, type),
            parameters);
    urlToRegistry = urlToRegistry.setScopeModel(directory.getConsumerUrl().getScopeModel());
    urlToRegistry = urlToRegistry.setServiceModel(directory.getConsumerUrl().getServiceModel());
    if (directory.isShouldRegister()) {
        //将构建好的urlToRegistry 字符串内容写到注册中心去
        directory.setRegisteredConsumerUrl(urlToRegistry);
        registry.register(directory.getRegisteredConsumerUrl());
    }
    //设置路由规则
    directory.buildRouterChain(urlToRegistry);
    //构建订阅的地址 subscribeUrl 然后发起订阅,然后会监听注册中心的目录
    directory.subscribe(toSubscribeUrl(urlToRegistry));

    return (ClusterInvoker<T>) cluster.join(directory, true);
}

    //构建订阅的地址 subscribeUrl 然后发起订阅,然后会监听注册中心的目录
    directory.subscribe(toSubscribeUrl(urlToRegistry));

doCreatorInvoker 主要做两件事:

1、向注册中心注册消费接口信息;

2、向注册中心订阅及监听

consumer://192.168.1.222/cn.uid.service.UidService?application=uap-sys-setting-application&background=false&check=false&check.serializable=false&dubbo=2.0.2&executor-management-mode=isolation&file-cache=true&interface=cn.uid.service.UidService&methods=getBatchIds,getDataCenterId,getNextId,getWorkerId&pid=26413&qos.enable=true&register-mode=instance&release=3.3.0-beta.4&retries=0&serialize.check.status=DISABLE&side=consumer&sticky=false&timeout=3000&timestamp=1722580295094&unloadClusterRelated=false

MigrationInvoker{serviceKey=cn.xxx.uid.service.UidService, invoker=null, step=null}

org.apache.dubbo.registry.client.migration.MigrationRuleListener#onRefer

服务提供方在远程导出时,利用Netty 绑定协议端口来提供服务,对应绑定端口的核心类是 NettyServer , 目前版本是:NettyPortUnificationServer

ServiceDiscoveryRegistryDirectory(registry: localhost:8848, subscribed key: cn.itbox.uap.uid.service.UidService)-Directory(invokers: 0[], validInvokers: 0[], invokersToReconnect: 0[])

org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory#subscribe

org.apache.dubbo.registry.client.ServiceDiscoveryRegistry#doSubscribe

添加事件

org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory.ConsumerConfigurationListener#addNotifyListener

org.apache.dubbo.registry.ListenerRegistryWrapper#subscribe

org.apache.dubbo.registry.client.ServiceDiscoveryRegistry#subscribe

Nacos

NacosServiceDiscovery.subscribe

org.apache.dubbo.registry.client.AbstractServiceDiscovery#subscribe

增加监听的接口

nacos://localhost:8848/org.apache.dubbo.registry.RegistryService?REGISTRY_CLUSTER=default:itbox-nacos&&check=false&check.serializable=false&dubbo=2.0.2&executor-management-mode=isolation&file-cache=true&interface=org.apache.dubbo.registry.RegistryService&namespace=itbox-nacos&pid=24139&qos.enable=true&register=true&register-mode=instance&release=3.3.0&erialize.check.status=DISABLE

TripleInvoker

org.apache.dubbo.remoting.transport.netty4.NettyConnectionClient [/192.168.0.246:64491 -> /192.168.0.246:8080] (Ref=1,local=/192.168.0.246:64491,remote=/192.168.0.246:8080

onEvent:217, NacosServiceDiscovery$NacosEventListener (org.apache.dubbo.registry.nacos)
onEvent:126, InstancesChangeNotifier (com.alibaba.nacos.client.naming.event)
onEvent:42, InstancesChangeNotifier (com.alibaba.nacos.client.naming.event)
lambda$notifySubscriber$0:199, DefaultPublisher (com.alibaba.nacos.common.notify)
run:-1, DefaultPublisher$$Lambda/0x0000007001b2ec90 (com.alibaba.nacos.common.notify)
notifySubscriber:206, DefaultPublisher (com.alibaba.nacos.common.notify)
receiveEvent:190, DefaultPublisher (com.alibaba.nacos.common.notify)
openEventHandler:112, DefaultPublisher (com.alibaba.nacos.common.notify)
run:95, DefaultPublisher (com.alibaba.nacos.common.notify)

netty4.NettyClient注册中心订阅及监听

之前doCreatorInvoker 注册了事件

在下面代码中设置断点

org.apache.dubbo.remoting.transport.netty4.NettyConnectionClient

org.apache.dubbo.remoting.transport.netty4.AbstractNettyConnectionClient#doConnect

设置断点

org.apache.dubbo.rpc.protocol.tri.TripleProtocol#refer

完整堆栈

refer:180, TripleProtocol (org.apache.dubbo.rpc.protocol.tri)
refer:112, ProtocolSecurityWrapper (org.apache.dubbo.rpc.protocol)
refer:85, QosProtocolWrapper (org.apache.dubbo.qos.protocol)
refer:86, ProtocolListenerWrapper (org.apache.dubbo.rpc.protocol)
refer:75, ProtocolFilterWrapper (org.apache.dubbo.rpc.cluster.filter)
refer:55, ProtocolSerializationWrapper (org.apache.dubbo.rpc.protocol)
refer:50, InvokerCountWrapper (org.apache.dubbo.rpc.protocol)
refer:-1, Protocol$Adaptive (org.apache.dubbo.rpc)
toInvokers:499, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
refreshInvoker:358, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
refreshOverrideAndInvoker:221, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
notify:213, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
lambda$notifyAddressChanged$10:467, ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener)
accept:-1, ServiceInstancesChangedListener$$Lambda/0x000000c001be5cb8 (org.apache.dubbo.registry.client.event.listener)
forEach:1603, ConcurrentHashMap (java.util.concurrent)
lambda$notifyAddressChanged$11:458, ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener)
get:-1, ServiceInstancesChangedListener$$Lambda/0x000000c001be5a98 (org.apache.dubbo.registry.client.event.listener)
post:76, MetricsEventBus (org.apache.dubbo.metrics.event)
post:59, MetricsEventBus (org.apache.dubbo.metrics.event)
notifyAddressChanged:455, ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener)
doOnEvent:243, ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener)
onEvent:125, ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener)
handleEvent:245, NacosServiceDiscovery (org.apache.dubbo.registry.nacos)
access$000:65, NacosServiceDiscovery (org.apache.dubbo.registry.nacos)
onEvent:217, NacosServiceDiscovery$NacosEventListener (org.apache.dubbo.registry.nacos)
onEvent:126, InstancesChangeNotifier (com.alibaba.nacos.client.naming.event)
onEvent:42, InstancesChangeNotifier (com.alibaba.nacos.client.naming.event)
lambda$notifySubscriber$0:199, DefaultPublisher (com.alibaba.nacos.common.notify)
run:-1, DefaultPublisher$$Lambda/0x000000c001b33720 (com.alibaba.nacos.common.notify)
notifySubscriber:206, DefaultPublisher (com.alibaba.nacos.common.notify)
receiveEvent:190, DefaultPublisher (com.alibaba.nacos.common.notify)
openEventHandler:112, DefaultPublisher (com.alibaba.nacos.common.notify)
run:95, DefaultPublisher (com.alibaba.nacos.common.notify)

设置断点

org.apache.dubbo.remoting.transport.netty4.NettyConnectionClient#initBootstrap

initBootstrap:58, NettyConnectionClient (org.apache.dubbo.remoting.transport.netty4)
doOpen:74, AbstractNettyConnectionClient (org.apache.dubbo.remoting.transport.netty4)
<init>:84, AbstractClient (org.apache.dubbo.remoting.transport)
<init>:52, AbstractConnectionClient (org.apache.dubbo.remoting.api.connection)
<init>:68, AbstractNettyConnectionClient (org.apache.dubbo.remoting.transport.netty4)
<init>:46, NettyConnectionClient (org.apache.dubbo.remoting.transport.netty4)
connect:33, NettyConnectionManager (org.apache.dubbo.remoting.transport.netty4)
lambda$connect$1:50, SingleProtocolConnectionManager (org.apache.dubbo.remoting.api.connection)
apply:-1, SingleProtocolConnectionManager$$Lambda/0x0000007001b56848 (org.apache.dubbo.remoting.api.connection)
compute:1916, ConcurrentHashMap (java.util.concurrent)
connect:44, SingleProtocolConnectionManager (org.apache.dubbo.remoting.api.connection)
connect:43, MultiplexProtocolConnectionManager (org.apache.dubbo.remoting.api.connection)
connect:42, NettyPortUnificationTransporter (org.apache.dubbo.remoting.transport.netty4)
connect:-1, PortUnificationTransporter$Adaptive (org.apache.dubbo.remoting.api.pu)
connect:64, PortUnificationExchanger (org.apache.dubbo.remoting.exchange)
refer:179, TripleProtocol (org.apache.dubbo.rpc.protocol.tri)
refer:86, ProtocolListenerWrapper (org.apache.dubbo.rpc.protocol)
refer:112, ProtocolSecurityWrapper (org.apache.dubbo.rpc.protocol)
refer:85, QosProtocolWrapper (org.apache.dubbo.qos.protocol)
refer:75, ProtocolFilterWrapper (org.apache.dubbo.rpc.cluster.filter)
refer:55, ProtocolSerializationWrapper (org.apache.dubbo.rpc.protocol)
refer:50, InvokerCountWrapper (org.apache.dubbo.rpc.protocol)
refer:-1, Protocol$Adaptive (org.apache.dubbo.rpc)
toInvokers:499, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
refreshInvoker:358, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
refreshOverrideAndInvoker:221, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
notify:213, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
addListenerAndNotify:269, ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener)
subscribeURLs:363, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
doSubscribe:244, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
subscribe:195, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
subscribe:87, ListenerRegistryWrapper (org.apache.dubbo.registry)
subscribe:186, DynamicDirectory (org.apache.dubbo.registry.integration)
subscribe:153, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
doCreateInvoker:666, RegistryProtocol (org.apache.dubbo.registry.integration)
getServiceDiscoveryInvoker:66, InterfaceCompatibleRegistryProtocol (org.apache.dubbo.registry.integration)
refreshServiceDiscoveryInvoker:458, MigrationInvoker (org.apache.dubbo.registry.client.migration)
migrateToForceApplicationInvoker:214, MigrationInvoker (org.apache.dubbo.registry.client.migration)
refreshInvoker:93, MigrationRuleHandler (org.apache.dubbo.registry.client.migration)
doMigrate:71, MigrationRuleHandler (org.apache.dubbo.registry.client.migration)
onRefer:285, MigrationRuleListener (org.apache.dubbo.registry.client.migration)
interceptInvoker:629, RegistryProtocol (org.apache.dubbo.registry.integration)
doRefer:593, RegistryProtocol (org.apache.dubbo.registry.integration)
refer:574, RegistryProtocol (org.apache.dubbo.registry.integration)
refer:83, ProtocolListenerWrapper (org.apache.dubbo.rpc.protocol)
refer:112, ProtocolSecurityWrapper (org.apache.dubbo.rpc.protocol)
refer:85, QosProtocolWrapper (org.apache.dubbo.qos.protocol)
refer:72, ProtocolFilterWrapper (org.apache.dubbo.rpc.cluster.filter)
refer:55, ProtocolSerializationWrapper (org.apache.dubbo.rpc.protocol)
refer:48, InvokerCountWrapper (org.apache.dubbo.rpc.protocol)
refer:-1, Protocol$Adaptive (org.apache.dubbo.rpc)
createInvoker:672, ReferenceConfig (org.apache.dubbo.config)
createProxy:502, ReferenceConfig (org.apache.dubbo.config)
init:383, ReferenceConfig (org.apache.dubbo.config)
get:244, ReferenceConfig (org.apache.dubbo.config)
get:140, SimpleReferenceCache (org.apache.dubbo.config.utils)
lambda$referServices$6:567, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
accept:-1, DefaultModuleDeployer$$Lambda/0x0000007001acf6d0 (org.apache.dubbo.config.deploy)
forEach:4783, ConcurrentHashMap$ValuesView (java.util.concurrent)
referServices:539, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
startSync:186, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
start:159, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
onContextRefreshedEvent:167, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
onApplicationEvent:153, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
onApplicationEvent:52, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
doInvokeListener:176, SimpleApplicationEventMulticaster (org.springframework.context.event)
invokeListener:169, SimpleApplicationEventMulticaster (org.springframework.context.event)
multicastEvent:143, SimpleApplicationEventMulticaster (org.springframework.context.event)
publishEvent:413, AbstractApplicationContext (org.springframework.context.support)
publishEvent:370, AbstractApplicationContext (org.springframework.context.support)
finishRefresh:937, AbstractApplicationContext (org.springframework.context.support)
refresh:587, AbstractApplicationContext (org.springframework.context.support)
refresh:732, SpringApplication (org.springframework.boot)
refreshContext:434, SpringApplication (org.springframework.boot)
run:310, SpringApplication (org.springframework.boot)
run:150, SpringApplicationBuilder (org.springframework.boot.builder)
main:51, OrgDemoApplication (cn.itbox.uap.demo.org.application)

设置断点

org.apache.dubbo.remoting.transport.netty4.AbstractNettyConnectionClient#doConnect

doConnect:115, AbstractNettyConnectionClient (org.apache.dubbo.remoting.transport.netty4)
connect:270, AbstractClient (org.apache.dubbo.remoting.transport)
<init>:97, AbstractClient (org.apache.dubbo.remoting.transport)
<init>:52, AbstractConnectionClient (org.apache.dubbo.remoting.api.connection)
<init>:68, AbstractNettyConnectionClient (org.apache.dubbo.remoting.transport.netty4)
<init>:46, NettyConnectionClient (org.apache.dubbo.remoting.transport.netty4)
connect:33, NettyConnectionManager (org.apache.dubbo.remoting.transport.netty4)
lambda$connect$1:50, SingleProtocolConnectionManager (org.apache.dubbo.remoting.api.connection)
apply:-1, SingleProtocolConnectionManager$$Lambda/0x0000007001b56848 (org.apache.dubbo.remoting.api.connection)
compute:1916, ConcurrentHashMap (java.util.concurrent)
connect:44, SingleProtocolConnectionManager (org.apache.dubbo.remoting.api.connection)
connect:43, MultiplexProtocolConnectionManager (org.apache.dubbo.remoting.api.connection)
connect:42, NettyPortUnificationTransporter (org.apache.dubbo.remoting.transport.netty4)
connect:-1, PortUnificationTransporter$Adaptive (org.apache.dubbo.remoting.api.pu)
connect:64, PortUnificationExchanger (org.apache.dubbo.remoting.exchange)
refer:179, TripleProtocol (org.apache.dubbo.rpc.protocol.tri)
refer:86, ProtocolListenerWrapper (org.apache.dubbo.rpc.protocol)
refer:112, ProtocolSecurityWrapper (org.apache.dubbo.rpc.protocol)
refer:85, QosProtocolWrapper (org.apache.dubbo.qos.protocol)
refer:75, ProtocolFilterWrapper (org.apache.dubbo.rpc.cluster.filter)
refer:55, ProtocolSerializationWrapper (org.apache.dubbo.rpc.protocol)
refer:50, InvokerCountWrapper (org.apache.dubbo.rpc.protocol)
refer:-1, Protocol$Adaptive (org.apache.dubbo.rpc)
toInvokers:499, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
refreshInvoker:358, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
refreshOverrideAndInvoker:221, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
notify:213, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
addListenerAndNotify:269, ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener)
subscribeURLs:363, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
doSubscribe:244, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
subscribe:195, ServiceDiscoveryRegistry (org.apache.dubbo.registry.client)
subscribe:87, ListenerRegistryWrapper (org.apache.dubbo.registry)
subscribe:186, DynamicDirectory (org.apache.dubbo.registry.integration)
subscribe:153, ServiceDiscoveryRegistryDirectory (org.apache.dubbo.registry.client)
doCreateInvoker:666, RegistryProtocol (org.apache.dubbo.registry.integration)
getServiceDiscoveryInvoker:66, InterfaceCompatibleRegistryProtocol (org.apache.dubbo.registry.integration)
refreshServiceDiscoveryInvoker:458, MigrationInvoker (org.apache.dubbo.registry.client.migration)
migrateToForceApplicationInvoker:214, MigrationInvoker (org.apache.dubbo.registry.client.migration)
refreshInvoker:93, MigrationRuleHandler (org.apache.dubbo.registry.client.migration)
doMigrate:71, MigrationRuleHandler (org.apache.dubbo.registry.client.migration)
onRefer:285, MigrationRuleListener (org.apache.dubbo.registry.client.migration)
interceptInvoker:629, RegistryProtocol (org.apache.dubbo.registry.integration)
doRefer:593, RegistryProtocol (org.apache.dubbo.registry.integration)
refer:574, RegistryProtocol (org.apache.dubbo.registry.integration)
refer:83, ProtocolListenerWrapper (org.apache.dubbo.rpc.protocol)
refer:112, ProtocolSecurityWrapper (org.apache.dubbo.rpc.protocol)
refer:85, QosProtocolWrapper (org.apache.dubbo.qos.protocol)
refer:72, ProtocolFilterWrapper (org.apache.dubbo.rpc.cluster.filter)
refer:55, ProtocolSerializationWrapper (org.apache.dubbo.rpc.protocol)
refer:48, InvokerCountWrapper (org.apache.dubbo.rpc.protocol)
refer:-1, Protocol$Adaptive (org.apache.dubbo.rpc)
createInvoker:672, ReferenceConfig (org.apache.dubbo.config)
createProxy:502, ReferenceConfig (org.apache.dubbo.config)
init:383, ReferenceConfig (org.apache.dubbo.config)
get:244, ReferenceConfig (org.apache.dubbo.config)
get:140, SimpleReferenceCache (org.apache.dubbo.config.utils)
lambda$referServices$6:567, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
accept:-1, DefaultModuleDeployer$$Lambda/0x0000007001acf6d0 (org.apache.dubbo.config.deploy)
forEach:4783, ConcurrentHashMap$ValuesView (java.util.concurrent)
referServices:539, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
startSync:186, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
start:159, DefaultModuleDeployer (org.apache.dubbo.config.deploy)
onContextRefreshedEvent:167, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
onApplicationEvent:153, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
onApplicationEvent:52, DubboDeployApplicationListener (org.apache.dubbo.config.spring.context)
doInvokeListener:176, SimpleApplicationEventMulticaster (org.springframework.context.event)
invokeListener:169, SimpleApplicationEventMulticaster (org.springframework.context.event)
multicastEvent:143, SimpleApplicationEventMulticaster (org.springframework.context.event)
publishEvent:413, AbstractApplicationContext (org.springframework.context.support)
publishEvent:370, AbstractApplicationContext (org.springframework.context.support)
finishRefresh:937, AbstractApplicationContext (org.springframework.context.support)
refresh:587, AbstractApplicationContext (org.springframework.context.support)
refresh:732, SpringApplication (org.springframework.boot)
refreshContext:434, SpringApplication (org.springframework.boot)
run:310, SpringApplication (org.springframework.boot)
run:150, SpringApplicationBuilder (org.springframework.boot.builder)
main:51, OrgDemoApplication (cn.itbox.uap.demo.org.application)

发起RPC调用

curl --location 'http://localhost:8090/org/ControllerToDubbo/getAllCity' \

--header 'x-gw-tag: 1'

org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory#subscribe

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值