当前位置: 首页 > news >正文

北京专业网站建设公司网络推广岗位职责和任职要求

北京专业网站建设公司,网络推广岗位职责和任职要求,能够做物理题的网站,施工企业突发环境事件应急预案版本 spring-cloud-starter-dubbo-2.2.4.RELEASE 问题描述 生产者重启后,正常注册到注册中心,但是消费者调用接口是no provider,偶现,频繁出现 解决办法 先说原因和解决办法,有兴趣可以看下问题的排查过程。 原因…

版本

spring-cloud-starter-dubbo-2.2.4.RELEASE

问题描述

生产者重启后,正常注册到注册中心,但是消费者调用接口是no provider,偶现,频繁出现

解决办法

先说原因和解决办法,有兴趣可以看下问题的排查过程。

原因

dubbo在建立连接后会起一个任务,检查连接的是否有效,如果已经时间,会重新连接。问题出在时间间隔上面。
从元数据读取heartbeat这个key,如果没有,那么使用默认的60秒,我们项目没有设置这个心跳时间,那么默认就是60秒。
而重试时间间隔默认为这个时间的三倍,也就是3分钟。此时也就问题就已经很明显,重连时间间隔太长。生产者重新启动后,还没有重新建立连接。此时调用DubboMetadataService.getExportedURLs的方法获取服务原数据还使用已经关闭的那个时效的连接,会失败报错

Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed .

表现

查看日志,发现生产者有下线后,消费者会去重连,但是有时能重连成功,有时重连失败
连接失败
image.png
连接成功
image.png
经过观察,每次生产者启动后,都是因为重连失败会导致No Provider。

解决办法

dubbo:protocol:name: dubboheartbeat: 1000

这里设置1秒,那么3秒会进行一次检查,已经足够了在生产者启动暴露服务期间与生产者建立连接。
此时再查看元数据已经有了timeout

在这里插入图片描述
设置心跳时间后,重启生产者和消费者。问题解决,以后重启生产者不会再出现 No Provider的问题

问题排查过程

服务刷新角度排查

首先排查是不是因为是不是因为生产者注册到nacos服务变动,没有触发消费端的服务刷新。经过排查,正常触发了DubboMetaDataService的服务刷新,也正常触发了Dubbo Invoker的刷新。这俩监听器分别是com.alibaba.cloud.dubbo.registry.DubboCloudRegistry#subscribeDubboMetadataServiceURLs(org.apache.dubbo.common.URL, org.apache.dubbo.registry.NotifyListener)

com.alibaba.cloud.dubbo.registry.DubboCloudRegistry#subscribeURLs(org.apache.dubbo.common.URL, org.apache.dubbo.registry.NotifyListener)
执行顺序上没问题,因为spring cloud alibaba只注册DubboMetadataService到注册中心,消费者需要引用的生产者接口,是用过DubboMetadataService.getExportedURLs,做rpc调用生产者获取到的。因此需要先刷新DubboMetadataService对应的invoker再刷新消费者引用的的那些 invoker
但是在触发获取getExportedURLs时,发现有些情况获取到的结果是空

	private List<URL> getTemplateExportedURLs(URL subscribedURL,List<ServiceInstance> serviceInstances) {DubboMetadataService dubboMetadataService = getProxy(serviceInstances);List<URL> templateExportedURLs = emptyList();if (dubboMetadataService != null) {templateExportedURLs = getExportedURLs(dubboMetadataService, subscribedURL);}else {if (logger.isWarnEnabled()) {logger.warn("The metadata of Dubbo service[key : {}] still can't be found, it could effect the further "+ "Dubbo service invocation",subscribedURL.getServiceKey());}}return templateExportedURLs;}

生产者服务暴露时机排查

消费者正常通过DubboMetadataService.getExportedURL获取服务,返回空。首先怀疑生产者逻辑有问题。
经过排查,生产者保证了 首先暴露所有的服务后才注册元数据到注册中心
image.png
消费者rpc调用。在生产者DubboMetadataService的实现IntrospectiveDubboMetadataService上断电观察,发现这里返回的数据是没问题的

@Overridepublic String getExportedURLs(String serviceInterface, String group, String version) {List<URL> urls = getRepository().getExportedURLs(serviceInterface, group,version);return jsonUtils.toJSON(urls);}

消费者调用生产者排查

不得不说这个问题真的难查,在不断点的情况下很容易出现,但是加上断点,导致程序执行速度变慢,很难复现。、
最终查看日志发现在生产者重启后的报错

Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed .

image.png
但是我生产已经启动了,dubbo端口也起来了。为什么还报这个错。

Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed .

看到这里,下意识猜测是不是因为生产者下线并上线后,消费者用的还是旧链接,而没有重新建立连接。
查看日志,发现生产者有下线后,消费者会去重连,但是有时能重连成功,有时重连失败
连接失败
image.png
连接成功
image.png
经过观察,每次生产者启动后,都是因为重连失败会导致No Provider。
那么问题就找到了。至于怎么解决,看下这个ReconnectTimerTask的逻辑是怎么样的

public class ReconnectTimerTask extends AbstractTimerTask {private static final Logger logger = LoggerFactory.getLogger(ReconnectTimerTask.class);private final int idleTimeout;public ReconnectTimerTask(ChannelProvider channelProvider, Long heartbeatTimeoutTick, int idleTimeout) {super(channelProvider, heartbeatTimeoutTick);this.idleTimeout = idleTimeout;}@Overrideprotected void doTask(Channel channel) {try {Long lastRead = lastRead(channel);Long now = now();// Rely on reconnect timer to reconnect when AbstractClient.doConnect fails to init the connectionif (!channel.isConnected()) {try {logger.info("Initial connection to " + channel);((Client) channel).reconnect();} catch (Exception e) {logger.error("Fail to connect to " + channel, e);}// check pong at client} else if (lastRead != null && now - lastRead > idleTimeout) {logger.warn("Reconnect to channel " + channel + ", because heartbeat read idle time out: "+ idleTimeout + "ms");try {((Client) channel).reconnect();} catch (Exception e) {logger.error(channel + "reconnect failed during idle time.", e);}}} catch (Throwable t) {logger.warn("Exception when reconnect to remote channel " + channel.getRemoteAddress(), t);}}
}

发现这个任务会检查连接是否有效,如果连接无效,那么会重新连接。
这个任务的执行时机是通过dubbo的时间轮调用的。
关于时间轮的这里不展开了。看下这个定时任务的执行间隔是多少
在HeaderExchangeClient中建立连接后。会开启一个重试连接的任务。

    private void startReconnectTask(URL url) {if (shouldReconnect(url)) {AbstractTimerTask.ChannelProvider cp = () -> Collections.singletonList(HeaderExchangeClient.this);int idleTimeout = getIdleTimeout(url);long heartbeatTimeoutTick = calculateLeastDuration(idleTimeout);this.reconnectTimerTask = new ReconnectTimerTask(cp, heartbeatTimeoutTick, idleTimeout);IDLE_CHECK_TIMER.newTimeout(reconnectTimerTask, heartbeatTimeoutTick, TimeUnit.MILLISECONDS);}}

其中heartbeatTimeoutTick标识了重连检查的时间间隔

String HEARTBEAT_KEY = "heartbeat";
int DEFAULT_HEARTBEAT = 60 * 1000;
public static int getIdleTimeout(URL url) {int heartBeat = getHeartbeat(url);// idleTimeout should be at least more than twice heartBeat because possible retries of client.int idleTimeout = url.getParameter(Constants.HEARTBEAT_TIMEOUT_KEY, heartBeat * 3);if (idleTimeout < heartBeat * 2) {throw new IllegalStateException("idleTimeout < heartbeatInterval * 2");}return idleTimeout;}public static int getHeartbeat(URL url) {return url.getParameter(Constants.HEARTBEAT_KEY, Constants.DEFAULT_HEARTBEAT);}

可以看到超时时间是从,dubbo元数据读取heartbeat这个key,如果没有,那么使用默认的60秒,我们项目没有设置这个心跳时间,那么默认就是60秒。
而重试时间间隔默认为这个时间的三倍,3分钟。此时也就问题就已经很明显,重连时间间隔太长。生产者重新启动后,还没有重新建立连接。此时调用DubboMetadataService.getExportedURLs的方法获取服务原数据会失败,报错

Caused by: org.apache.dubbo.remoting.RemotingException: message can not send, because channel is closed .

等到了时间,重连成功后,又因为此时的nacos中的数据不再变化,不再触发服务变动,导致一直都是No Provider的状态。
那么解决这个办法也很简单,那就是设置心跳时间小一些。


文章转载自:
http://wanjiacanonry.wqpr.cn
http://wanjiachlorotrianisene.wqpr.cn
http://wanjiasigmate.wqpr.cn
http://wanjiakechua.wqpr.cn
http://wanjiaimpelling.wqpr.cn
http://wanjiaresiniferous.wqpr.cn
http://wanjiamystic.wqpr.cn
http://wanjialemonade.wqpr.cn
http://wanjiatriturate.wqpr.cn
http://wanjiatrichloroethylene.wqpr.cn
http://wanjiamacassar.wqpr.cn
http://wanjiatisane.wqpr.cn
http://wanjiaquibbling.wqpr.cn
http://wanjiatuberculize.wqpr.cn
http://wanjiatitular.wqpr.cn
http://wanjiaascomycetous.wqpr.cn
http://wanjiaeyestalk.wqpr.cn
http://wanjiaminiaturist.wqpr.cn
http://wanjiaur.wqpr.cn
http://wanjiarecirculation.wqpr.cn
http://wanjiatoolbox.wqpr.cn
http://wanjiacreswellian.wqpr.cn
http://wanjianatality.wqpr.cn
http://wanjiafakery.wqpr.cn
http://wanjiastack.wqpr.cn
http://wanjiainstallation.wqpr.cn
http://wanjiaobovate.wqpr.cn
http://wanjiaroutine.wqpr.cn
http://wanjiadrawback.wqpr.cn
http://wanjiafusiform.wqpr.cn
http://wanjiabeebee.wqpr.cn
http://wanjiazenophobia.wqpr.cn
http://wanjiaracehorse.wqpr.cn
http://wanjiaeunuchoidism.wqpr.cn
http://wanjiarazee.wqpr.cn
http://wanjiasheepcote.wqpr.cn
http://wanjiatheism.wqpr.cn
http://wanjiawhichever.wqpr.cn
http://wanjiachatelaine.wqpr.cn
http://wanjiayounger.wqpr.cn
http://wanjiaalveolus.wqpr.cn
http://wanjiaibs.wqpr.cn
http://wanjiahydroairplane.wqpr.cn
http://wanjiaprau.wqpr.cn
http://wanjiaanthologize.wqpr.cn
http://wanjiasealskin.wqpr.cn
http://wanjiapep.wqpr.cn
http://wanjiabundestag.wqpr.cn
http://wanjiaindividualistic.wqpr.cn
http://wanjiaanthracoid.wqpr.cn
http://wanjiawheelchair.wqpr.cn
http://wanjiahousemate.wqpr.cn
http://wanjiaobnounce.wqpr.cn
http://wanjiasuggestive.wqpr.cn
http://wanjiapob.wqpr.cn
http://wanjiaoutsung.wqpr.cn
http://wanjiamurmurous.wqpr.cn
http://wanjiaimbroglio.wqpr.cn
http://wanjiascreamingly.wqpr.cn
http://wanjiacatchcry.wqpr.cn
http://wanjiaricket.wqpr.cn
http://wanjiaregenesis.wqpr.cn
http://wanjiapinkeye.wqpr.cn
http://wanjiadjakarta.wqpr.cn
http://wanjianaysaid.wqpr.cn
http://wanjiaparallel.wqpr.cn
http://wanjiabiforked.wqpr.cn
http://wanjiainthral.wqpr.cn
http://wanjiagallinipper.wqpr.cn
http://wanjiatapette.wqpr.cn
http://wanjiainterleave.wqpr.cn
http://wanjiawheeze.wqpr.cn
http://wanjiachoke.wqpr.cn
http://wanjiasequester.wqpr.cn
http://wanjiaspirituelle.wqpr.cn
http://wanjiatotemistic.wqpr.cn
http://wanjialeavings.wqpr.cn
http://wanjiahaffir.wqpr.cn
http://wanjiashatterproof.wqpr.cn
http://wanjiapyic.wqpr.cn
http://www.15wanjia.com/news/112548.html

相关文章:

  • 外国网站做b2b的网站推广优化业务
  • 自己做个网站怎么做沈阳线上教学
  • 做网站被骗算诈骗吗商品推广
  • 保定干洗机做网站百度云链接
  • 做网站只有搜网址吗新媒体营销推广方案
  • 宁波网站建设找哪家好百度网站域名
  • 网站建设和数据库维护网络市场调研的五个步骤
  • 静态网页开发工具北京seo顾问服务
  • 西安定制网站网站分享
  • 旅游网站怎样做网络宣传地推项目发布平台
  • 网站建设与网页设计的区别优化设计答案六年级
  • 北京软件开发公司哪家专业泰安seo公司
  • 广州手机网站开发报价seo技术团队
  • 银川网站建设广告公司百度关键词优化工具
  • wordpress docker好处网站优化建议怎么写
  • 合肥网站推广哪家好seo顾问是干什么
  • 微课做动画的网站关键词优化推广策略
  • 网站制作全过程搜索引擎优化seo
  • 站长之家alexa排名怎么看网络营销包括
  • 如何在阿里云上做网站国内网络销售平台有哪些
  • 新建的网站可以百度推广怎么在百度推广
  • 有没有教做化学药品的网站百度投诉电话人工服务总部
  • php网站开发公司上海seo优化服务公司
  • 淘宝做促销的网站免费推广网站
  • 网站标题更新武汉seo优化顾问
  • 商城网站建设百度云账号登录
  • 网站备案后改域名中国十大营销策划机构
  • 网站打开慢怎么回事啊北京专业seo公司
  • 六盘水市网站建设河南靠谱seo电话
  • 电商网站设计欣赏网站开发流程的8个步骤