本文主要是介绍dubbo3 consumer消费端重启调用接口有30多秒等待问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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×tamp=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×tamp=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×tamp=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熟悉的大佬给出解决方案
如果解决我会更新在文章中。。。。
外传
😜 原创不易,如若本文能够帮助到您的同学
🎉 支持我:关注我+点赞👍+收藏⭐️
📝 留言:探讨问题,看到立马回复
💬 格言:己所不欲勿施于人 扬帆起航、游历人生、永不言弃!🔥
这篇关于dubbo3 consumer消费端重启调用接口有30多秒等待问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!