本人微信公众号文章链接:https://mp.weixin.qq.com/s/wNULJpEr9g3TlGAhD8JuKg
Tars是腾讯开源的一款微服务框架。在去年9月,腾讯宣布正式开源 Tars 的 Golang 版本TarsGo。
当TarGo开源的时候,就想对此开源代码进行学习。近期刚好有空,就看了看。说实话,本人并未使用Tars框架,本文只是对TarsGo源码进行分析。
Tars整体框架介绍,可以参考https://github.com/TarsCloud/Tars/blob/master/Introduction.md
还有文章:
腾讯 Tars 开源 Go 版本 Tars-Go,并发性能比 gRPC 高 5 倍
https://my.oschina.net/editorial-story/blog/2054185
关于TarsGo的介绍还有:
https://github.com/TarsCloud/TarsGo/blob/master/README.zh.md
源码地址:
https://github.com/TarsCloud/TarsGo
按照本人习惯,从低版本进行研究,此次源码分析定位v1.0.0版本
源码目录:
在Tarsgo中,有两个模块client和server
此图来源https://github.com/TarsCloud/Tars/blob/master/Introduction.md
https://github.com/TarsCloud/Tars/blob/master/Introduction.md
server服务运行后,会定期上报心跳到node,node然后把服务心跳信息上报到registry服务,由registry进行统一管理。 Client访问Server流程:client可以通过server的对象名Obj间接访问server,Client会从registry上拉取server的路由信息(如ip、port信息),然后根据具体的业务特性(同步或者异步,tcp或者udp方式)访问server(当然client也可以通过ip/port直接访问server)。
https://github.com/TarsCloud/Tars/blob/master/Introduction.md
在github.com/TarsCloud/TarsGo/tars/tools/Demo中有构建client和server,这将是源码开始的第一步。
transport
在此之前,有一个底层模块很独立,会优先分析
transport模块,是一个完全独立的模块,其中有底层的tarclient和tarserver模块。
在github.com/TarsClou