「连载」边缘计算(二十八)03-08:边缘部分源码(源码分析篇)

(接上篇)

eventbus 的具体逻辑剖析

从eventbus的启动函数切入分析具体逻辑,具体如下所示。

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| KubeEdge/edge/pkg/eventbus/event_bus.go |
| func (eb *eventbus) Start(c *context.Context) { // no need to call TopicInit now, we have fixed topic eb.context = c nodeID := config.CONFIG.GetConfigurationByKey("edgehub.controller.node-id") ... mqttBus.NodeID = nodeID.(string) mqttBus.ModuleContext = c if eb.mqttMode >= bothMqttMode { // launch an external mqtt server externalMqttURL := config.CONFIG.GetConfigurationByKey("mqtt.server") ... hub := &mqttBus.Client{ MQTTUrl: externalMqttURL.(string), } mqttBus.MQTTHub = hub hub.InitSubClient() hub.InitPubClient() } if eb.mqttMode <= bothMqttMode { internalMqttURL := config.CONFIG.GetConfigurationByKey("mqtt.internal-server") ... qos := config.CONFIG.GetConfigurationByKey("mqtt.qos") ... retain := config.CONFIG.GetConfigurationByKey("mqtt.retain") ... sessionQueueSize := config.CONFIG.GetConfigurationByKey("mqtt.session-queue-size") ... if qos.(int) < int(packet.QOSAtMostOnce) || qos.(int) > int(packet.QOSExactlyOnce) || sessionQueueSize.(int) <= 0 { klog.Errorf("mqtt.qos must be one of [0,1,2] or mqtt.session-queue-size must > 0") os.Exit(1) } // launch an internal mqtt server only mqttServer = mqttBus.NewMqttServer(sessionQueueSize.(int), internalMqttURL.(string), retain.(bool), qos.(int)) mqttServer.InitInternalTopics() err := mqttServer.Run() ... } eb.pubCloudMsgToEdge() } |

eventbus的启动函数做了如下3件事。

1) 处理eventbus模块的公共配置,具体如下所示。

|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| eb.context = c nodeID := config.CONFIG.GetConfigurationByKey("edgehub.controller.node-id") ... mqttBus.NodeID = nodeID.(string) mqttBus.ModuleContext = c |

接收并存储与EdgeCore其他模块通信的管道,从配置文件中获取所在节点的唯一标识。

2) 根据不同mqttMode启动与mqtt交互的不同实例,具体如下所示。

|---------------------------------------------------------------------------------|
| if eb.mqttMode >= bothMqttMode { ... } if eb.mqttMode <= bothMqttMode { ... } |

当 eb.mqttMode >= bothMqttMode将mqtt代理启动在eventbus之外,eventbus作为独立启动的mqtt代理的客户端与其交互;当eb.mqttMode <= bothMqttMode时,在eventbus内启动一个mqtt代理,负责与终端设备交互。

3)将云部分的指令和事件下发到与eventbus相连的设备,具体如下所示。

|------------------------|
| eb.pubCloudMsgToEdge() |

未完待续......

相关推荐
天辛大师1 分钟前
江南居士林:天辛大师浅谈如何用AI分辨明前茶还是雨前茶
大数据·人工智能·决策树·随机森林·启发式算法
刘~浪地球5 分钟前
AI幻觉正在“吃掉“信任:一次保险购买引发的血案
人工智能·深度学习·机器学习
AI视觉网奇21 分钟前
公式动画软件学习笔记
人工智能·公式绘图
天天代码码天天24 分钟前
C# OnnxRuntime 部署 DDColor
人工智能·ddcolor
惠惠软件25 分钟前
豆包 AI 学习投喂与排名优化指南
人工智能·学习·语音识别
数据中心的那点事儿26 分钟前
从设计到运营全链破局 恒华智算专场解锁产业升级密码
大数据·人工智能
FluxMelodySun30 分钟前
机器学习(三十三) 概率图模型与隐马尔可夫模型
人工智能·机器学习
深兰科技35 分钟前
深兰科技与淡水河谷合作推进:矿区示范加速落地
java·人工智能·python·c#·scala·symfony·深兰科技
V搜xhliang024639 分钟前
OpenClaw、AI大模型赋能数据分析与学术科研 学习
人工智能·深度学习·学习·机器学习·数据挖掘·数据分析
PHOSKEY41 分钟前
3D工业相机对焊后缺陷全检——机械手焊接系统质量控制的最后关口
人工智能