Broker


与Namesrv的关系

1.从namesrv获取配置信息

 /**
* BrokerConfig类
*
* broker每隔30秒(此时间无法更改)向所有nameserver发送心跳,心跳包含了自身的topic配置信息。
* 这里的“此时间无法更改”是别人的总结,还没搞懂为啥此时间不可更改,明明原版注释中写的是取值范围在10,000到60,000之间
*
* This configurable item defines interval of topics registration of broker to name server. Allowing values are
* between 10, 000 and 60, 000 milliseconds.
*/
private int registerNameServerPeriod = 1000 * 30;

2.namesrv检查broker的心跳

         /**
* NamesrvController类
* Namesrv定时检查Broker心跳
* 每10秒检查一次,时间戳超过2分钟,则认为Broker失效,从brokerLiveTable中移除
*/
this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override
public void run() {
NamesrvController.this.routeInfoManager.scanNotActiveBroker();
}
}, 5, 10, TimeUnit.SECONDS); ... /**
* RouteInfoManager类
* Namesrv查看不活跃|失效的Broker
*/
public void scanNotActiveBroker() {
Iterator<Entry<String, BrokerLiveInfo>> it = this.brokerLiveTable.entrySet().iterator();
while (it.hasNext()) {
Entry<String, BrokerLiveInfo> next = it.next();
long last = next.getValue().getLastUpdateTimestamp();
if ((last + BROKER_CHANNEL_EXPIRED_TIME) < System.currentTimeMillis()) {
RemotingUtil.closeChannel(next.getValue().getChannel());
it.remove();
log.warn("The broker channel expired, {} {}ms", next.getKey(), BROKER_CHANNEL_EXPIRED_TIME);
this.onChannelDestroy(next.getKey(), next.getValue().getChannel());
}
}
}

3.Namesrv检查与Broker的长连接

 /**
* BrokerHousekeepingService类
* 当NameServer和Broker的长连接断掉以后,onChannelDestroy函数会被调用,把这个Broker的信息清理出去。
*/
@Override
public void onChannelClose(String remoteAddr, Channel channel) {
this.namesrvController.getRouteInfoManager().onChannelDestroy(remoteAddr, channel);
} /**
* BrokerHousekeepingService类
* 当NameServer和Broker的长连接断掉以后,onChannelDestroy函数会被调用,把这个Broker的信息清理出去。
*/
@Override
public void onChannelException(String remoteAddr, Channel channel) {
this.namesrvController.getRouteInfoManager().onChannelDestroy(remoteAddr, channel);
} /**
* BrokerHousekeepingService类
* 当NameServer和Broker的长连接断掉以后,onChannelDestroy函数会被调用,把这个Broker的信息清理出去。
*/
@Override
public void onChannelIdle(String remoteAddr, Channel channel) {
this.namesrvController.getRouteInfoManager().onChannelDestroy(remoteAddr, channel);
}

Consumer|Producer


与Namesrv的关系

     /**
* ClientConfig类
*
* 默认情况下,消费者每隔30秒从nameserver获取所有topic的最新队列情况,
* 这意味着某个broker如果宕机,客户端最多要30秒才能感知。
*
* 默认情况下,生产者每隔30秒从nameserver获取所有topic的最新队列情况,
* 这意味着某个broker如果宕机,生产者最多要30秒才能感知,在此期间,发往该broker的消息发送失败。
*
* Pulling topic information interval from the named server
*/
private int pollNameServerInterval = 1000 * 30;

与Broker的关系

1.客户端(生产者|消费者)向Broker发送心跳

     /**
* ClientConfig类
*
* 默认情况下,消费者|生产者 每隔30秒向所有broker发送心跳
*
* Heartbeat interval in microseconds with message broker
*/
private int heartbeatBrokerInterval = 1000 * 30;

2.Broker定期检查客户端心跳检查

     /**
* ClientHousekeepingService类
*
* Broker定时清理不活动的客户端(生产者|消费者)连接
* 每10秒检查一次,时间戳超过2分钟,则关闭客户端(生产者|消费者)连接
*/
public void start() { this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
try {
ClientHousekeepingService.this.scanExceptionChannel();
} catch (Throwable e) {
log.error("Error occurred when scan not active client channels.", e);
}
}
}, 1000 * 10, 1000 * 10, TimeUnit.MILLISECONDS);
} ... /**
* ClientHousekeepingService类
*
* Broker定时清理不活动的客户端(生产者|消费者)连接
* 每10秒检查一次,时间戳超过2分钟,则关闭客户端(生产者|消费者)连接
*/
private void scanExceptionChannel() {
this.brokerController.getProducerManager().scanNotActiveChannel();
this.brokerController.getConsumerManager().scanNotActiveChannel();
this.brokerController.getFilterServerManager().scanNotActiveChannel();
}

3.Broker检查与客户端的长连接

     /**
* ClientHousekeepingService类
*
* 当客户端(Producer|Consumer)和Broker的长连接断掉以后,doChannelCloseEvent函数会被调用,把对应客户端(Producer|Consumer)断开连接
*/
@Override
public void onChannelClose(String remoteAddr, Channel channel) {
this.brokerController.getProducerManager().doChannelCloseEvent(remoteAddr, channel);
this.brokerController.getConsumerManager().doChannelCloseEvent(remoteAddr, channel);
this.brokerController.getFilterServerManager().doChannelCloseEvent(remoteAddr, channel);
} /**
* ClientHousekeepingService类
*
* 当客户端(Producer|Consumer)和Broker的长连接断掉以后,doChannelCloseEvent函数会被调用,把对应客户端(Producer|Consumer)断开连接
*/
@Override
public void onChannelException(String remoteAddr, Channel channel) {
this.brokerController.getProducerManager().doChannelCloseEvent(remoteAddr, channel);
this.brokerController.getConsumerManager().doChannelCloseEvent(remoteAddr, channel);
this.brokerController.getFilterServerManager().doChannelCloseEvent(remoteAddr, channel);
} /**
* ClientHousekeepingService类
*
* 当客户端(Producer|Consumer)和Broker的长连接断掉以后,doChannelCloseEvent函数会被调用,把对应客户端(Producer|Consumer)断开连接
*/
@Override
public void onChannelIdle(String remoteAddr, Channel channel) {
this.brokerController.getProducerManager().doChannelCloseEvent(remoteAddr, channel);
this.brokerController.getConsumerManager().doChannelCloseEvent(remoteAddr, channel);
this.brokerController.getFilterServerManager().doChannelCloseEvent(remoteAddr, channel);
}

结合别人的文章,做RocketMQ的一点原理分析,结合源码(尽量)----未完待续的更多相关文章

  1. 分析jQuery源码时记录的一点感悟

    分析jQuery源码时记录的一点感悟      1.  链式写法      这是jQuery语法上的最大特色,也许该改改POJO里的set方法,和其他的非get方法什么的,可以把多行代码合并,减去每次 ...

  2. RocketMQ中Broker的HA策略源码分析

    Broker的HA策略分为两部分①同步元数据②同步消息数据 同步元数据 在Slave启动时,会启动一个定时任务用来从master同步元数据 if (role == BrokerRole.SLAVE) ...

  3. Spring Boot 2.0系列文章(五):Spring Boot 2.0 项目源码结构预览

    关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/15/springboot2_code/ 项目结构 结构分析: Spring-boot-pr ...

  4. [已开源/文章教程]独立开发 一个社交 APP 的源码/架构分享 (已上架)

    0x00 背景 真不是和被推荐了2天的博客园一位大神较真,从他那篇文章的索引式文章内容也学习到了很多东西,看评论区那么多对社交APP源码有兴趣的,正巧我上周把我的一个社交APP开源了,包括androi ...

  5. Android应用系列:手把手教你做一个小米通讯录(附图附源码)

    前言 最近心血来潮,突然想搞点仿制品玩玩,很不幸小米成为我苦逼的第一个试验品.既然雷布斯的MIUI挺受欢迎的(本人就是其的屌丝用户),所以就拿其中的一些小功能做一些小demo来玩玩.小米的通讯录大家估 ...

  6. RocketMQ中Broker的刷盘源码分析

    上一篇博客的最后简单提了下CommitLog的刷盘  [RocketMQ中Broker的消息存储源码分析] (这篇博客和上一篇有很大的联系) Broker的CommitLog刷盘会启动一个线程,不停地 ...

  7. 用javascript和html5做一个音乐播放器,附带源码

    效果图: 实现的功能 1.首页 2.底部播放控件 3.播放页面 4.播放列表 5.排行榜 6.音乐搜索 输入搜索关键词,点击放大镜图标 7.侧边栏 目录结构 开发心得与总结 1.轮播图 首先感谢作者S ...

  8. JS和H5做一个音乐播放器,附带源码

    http://mp.weixin.qq.com/s/KpXT9X46AMlUVXQvpHuXGQ 效果图: 实现的功能 1.首页 2.底部播放控件 3.播放页面 4.播放列表 5.排行榜 6.音乐搜索 ...

  9. 使用jquery.validation+jquery.poshytip做表单验证--未完待续

    jqueryValidate的具体使用方法很多,这里就不在赘述,这一次只谈一下怎样简单的实现表单验证. 整片文章目的,通过JQvalidation按表单属性配置规则验证,并将验证结果通过poshyti ...

随机推荐

  1. 浅谈TCP IP协议栈(一)入门知识【转】

    说来惭愧,打算写关于网络方面的知识很久了,结果到今天才正式动笔,好了,废话不多说,写一些自己能看懂的入门知识,对自己来说是一种知识的总结,也希望能帮到一些想了解网络知识的童鞋. 万事开头难,然后中间难 ...

  2. swift修改UITextfield的Placeholder字体大小和颜色

    第一种方法: self.userNumber.setValue(UIColor.lightGray, forKey: "_placeholderLabel.textColor") ...

  3. docker 基础

    概述 起源 2013 年由 DotCloud 公司开源出来的容器管理工具 DotCloud 公司是一家 PAAS 服务提供商,从 docker 的出身也可以看出它的主要功能和方向 技术原理 开始时是基 ...

  4. Docker: 企业级镜像仓库Harbor部署(http)

    Harbor离线安装包下载地址:https://github.com/goharbor/harbor Docker compose(安装harbor需要用到docker compose)下载地址:ht ...

  5. 使用opencv进行简单的手势检测[by Python]

    代码参考于:https://github.com/rainyear/lolita/issues/8 简单的手势识别,基本思路是基于皮肤检测,皮肤的颜色在HSV颜色空间下与周围环境的区分度更高,从RGB ...

  6. UVALive - 5135 - Mining Your Own Business(双连通分量+思维)

    Problem   UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John D ...

  7. Qt License 解读

    对于桌面和移动平台应用 官方说明如下 Qt for Application Development lets you create applications for desktop and mobil ...

  8. (十四)Exploring Your Data

    Sample Dataset Now that we’ve gotten a glimpse of the basics, let’s try to work on a more realistic ...

  9. cpu_ops、suspend_ops、arm_idle_driver以及machine_restart/machine_power_off到底层PSCI Firmware分析

    在内核中针对的cpu的操作,比如arm_cpuidle_init.arm_cpuidle_suspend.boot_secondary.secondary_start_kernel.op_cpu_di ...

  10. Linux内存管理 (19)总结内存管理数据结构和API

    专题:Linux内存管理专题 关键词:mm.vaddr.VMA.page.pfn.pte.paddr.pg_data.zone.mem_map[]. 1. 内存管理数据结构的关系图 在大部分Linux ...