dubbo3 consumer消费端重启调用接口有30多秒等待问题

文章讨论了Dubbo3消费者在SpringBoot应用启动后,由于服务注册到Nacos的延迟导致的接口调用等待问题,分析了原因并提出了期望的优化方案,包括在Spring启动前完成Dubbo服务注册和减少注册时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、问题

Dubbo3 consumer消费端重启后,立即调用接口,需要等待有30多秒或者更久

之前没有加dubbo日志,所以 restful请求进去,直接卡住了,一直等待30多秒左右

加上dubbo日志后

2023-12-29 11:26:55.868 [main] INFO  o.s.scheduling.concurrent.ThreadPoolTaskExecutor traceId: - Initializing ExecutorService 'applicationTaskExecutor'
2023-12-29 11:26:55.957 [main] INFO  com.xxxx.common.restful.config.WebConfiguration traceId: - 增加拦截器
2023-12-29 11:26:57.505 [main] WARN  o.s.b.a.freemarker.FreeMarkerAutoConfiguration traceId: - Cannot find template location(s): [classpath:/templates/] (please add some templates, check your FreeMarker configuration, or set spring.freemarker.checkTemplateLocation=false)
2023-12-29 11:26:57.622 [main] INFO  org.apache.coyote.http11.Http11NioProtocol traceId: - Starting ProtocolHandler ["http-nio-8081"]
2023-12-29 11:26:57.654 [main] INFO  o.s.boot.web.embedded.tomcat.TomcatWebServer traceId: - Tomcat started on port(s): 8081 (http) with context path ''
2023-12-29 11:26:57.719 [main] INFO  o.apache.dubbo.config.deploy.DefaultModuleDeployer traceId: -  [DUBBO] Dubbo Module[1.1.1] is starting., dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:57.720 [main] INFO  o.a.dubbo.config.deploy.DefaultApplicationDeployer traceId: -  [DUBBO] Dubbo Application[1.1](xy-xxxx-common-restful) is starting., dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:57.720 [main] INFO  o.apache.dubbo.config.deploy.DefaultModuleDeployer traceId: -  [DUBBO] Dubbo Module[1.1.0] is starting., dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:57.721 [main] INFO  o.apache.dubbo.config.deploy.DefaultModuleDeployer traceId: -  [DUBBO] Dubbo Module[1.1.0] has started., dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:57.911 [main] INFO  org.apache.dubbo.metadata.MappingCacheManager traceId: -  [DUBBO] Successfully loaded mapping cache from file .mapping.xy-xxxx-common-restful, entries 0, dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:58.044 [main] INFO  org.apache.dubbo.qos.protocol.QosProtocolWrapper traceId: -  [DUBBO] qos won't be started because it is disabled. Please check dubbo.application.qos.enable is configured either in system property, dubbo.properties or XML/spring-boot configuration., dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:58.197 [main] INFO  c.a.n.p.auth.spi.client.ClientAuthPluginManager traceId: - [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.impl.NacosClientAuthServiceImpl success.
2023-12-29 11:26:58.198 [main] INFO  c.a.n.p.auth.spi.client.ClientAuthPluginManager traceId: - [ClientAuthPluginManager] Load ClientAuthService com.alibaba.nacos.client.auth.ram.RamClientAuthServiceImpl success.
2023-12-29 11:26:58.379 [main] INFO  org.apache.dubbo.registry.nacos.NacosRegistry traceId: -  [DUBBO] Loaded registry cache file /home/www/.dubbo/dubbo-registry-xy-xxxx-common-restful-10.255.20.232-8848.cache, dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:58.420 [main] INFO  o.a.d.r.client.migration.MigrationRuleListener traceId: -  [DUBBO] Listening for migration rules on dataId xy-xxxx-common-restful.migration, group DUBBO_SERVICEDISCOVERY_MIGRATION, dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:58.585 [main] INFO  org.apache.dubbo.registry.nacos.NacosRegistry traceId: -  [DUBBO] Subscribe: consumer://172.17.0.1/com.xxxx.common.api.service.ElecSignDubboService?application=xy-xxxx-common-restful&background=false&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=com.xxxx.common.api.service.ElecSignDubboService&lazy=false&logger=slf4j&methods=signContractAfterOtherOpt,selectEsignLogPage,optEsignFlow,selectEsignMealLog,signContractOrFileToEsign,selectEsignPage,eSignCallBackHandle,selectEsignDetail,signAgreementToEsign,selectEsignMealDetail,mealConfig,lookFile&pid=22366&qos.enable=false&reference.filter=traceIdFilter&release=3.1.0&retries=0&side=consumer&sticky=false&timeout=60000&timestamp=1703820417861, dubbo version: 3.1.0, current host: 172.17.0.1
2023-12-29 11:26:58.629 [main] WARN  org.apache.dubbo.registry.nacos.NacosRegistry traceId: -  [DUBBO] Ignore empty notify urls for subscribe url consumer://172.17.0.1/com.xxxx.common.api.service.ElecSignDubboService?application=xy-xxxx-common-restful&background=false&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=com.xxxx.common.api.service.ElecSignDubboService&lazy=false&logger=slf4j&methods=signContractAfterOtherOpt,selectEsignLogPage,optEsignFlow,selectEsignMealLog,signContractOrFileToEsign,selectEsignPage,eSignCallBackHandle,selectEsignDetail,signAgreementToEsign,selectEsignMealDetail,mealConfig,lookFile&pid=22366&qos.enable=false&reference.filter=traceIdFilter&release=3.1.0&retries=0&side=consumer&sticky=false&timeout=60000&timestamp=1703820417861, dubbo version: 3.1.0, current host: 172.17.0.1, error code: 1-4. This may be caused by , go to https://dubbo.apache.org/faq/1/4 to find instructions. 
2023-12-29 11:26:58.633 [main] WARN  org.apache.dubbo.registry.nacos.NacosRegistry traceId: -  [DUBBO] Ignore empty notify urls for subscribe url consumer://172.17.0.1/com.xxxx.common.api.service.ElecSignDubboService?application=xy-xxxx-common-restful&background=false&category=providers,configurators,routers&check=false&dubbo=2.0.2&interface=com.xxxx.common.api.service.ElecSignDubboService&lazy=false&logger=slf4j&methods=signContractAfterOtherOpt,selectEsignLogPage,optEsignFlow,selectEsignMealLog,signContractOrFileToEsign,selectEsignPage,eSignCallBackHandle,selectEsignDetail,signAgreementToEsign,selectEsignMealDetail,mealConfig,lookFile&pid=22366&qos.enable=false&reference.filter=traceIdFilter&release=3.1.0&retries=0&side=consumer&sticky=false&timeout=60000&timestamp=1703820417861, dubbo version: 3.1.0, current host: 172.17.0.1, error code: 1-4. This may be caused by , go to https://dubbo.apache.org/faq/1/4 to find instructions. 

2、版本号

springboot 2.3.1.RELEASE
dubbo 3.1.0
nacos 2.1

3、问题原因

原因就在于,springboot在暴露端口后,去发布事件和监听时去把dubbo服务注册到naocs,一直在执行注册过程,所以,才会出现调用接口时等待

分析:
在SpringApplication.class run方法中,执行到this.refreshContext(context)方法中,然后到
AbstractApplicationContext.class中的refresh()方法中,finishRefresh(),方法中

protected void finishRefresh() {
    // Clear context-level resource caches (such as ASM metadata from scanning).
    clearResourceCaches();

    // Initialize lifecycle processor for this context.
    initLifecycleProcessor();

    // Propagate refresh to lifecycle processor first.
    getLifecycleProcessor().onRefresh();

    // Publish the final event.
    publishEvent(new ContextRefreshedEvent(this));

    // Participate in LiveBeansView MBean, if active.
    LiveBeansView.registerApplicationContext(this);
}

执行pubishEvent时dubbo服务去注册到nacos,这个时候,springboot的onRefresh()已经执行了,相当于已经暴露项目的端口了,
再去注册,这个时候,如果服务很多需要订阅的情况下,需要很久,所以,这块取决于服务有多少了。。

这样就会出现一个问题,既然项目模块已经暴露端口了,项目端口和接口已经对外可用状态了,但是服务还正在注册到nacos过程中,调用就会等待很久(取决于订阅的服务数量,我这有300多个)这个问题怎么解决呢??

查阅 了,很多的资料和dubbo官网的配置参数,nacos的配置参数,尝试了很多,是dubbo2和dubbo3的在spring加载时的机制变了,但这个问题怎么搞 ?

4、想要的预期结果

1、springboot暴露端口前,也就是在getLifecycleProcessor().onRefresh()前,dubbo服务注册到nacos完成
2、减少dubbo注册到nacos的过程时间
3、采用懒加载方式(但不太想使用这种方式)

5、重点来了,现在还没有解决

有空还在查dubb3和nacos2.1源码当中。。。
欢迎各位dubbo3熟悉的大佬给出解决方案
如果解决我会更新在文章中。。。。

外传

😜 原创不易,如若本文能够帮助到您的同学
🎉 支持我:关注我+点赞👍+收藏⭐️
📝 留言:探讨问题,看到立马回复
💬 格言:己所不欲勿施于人 扬帆起航、游历人生、永不言弃!🔥

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南巷Dong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值