In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to migrate go-zero in enterprise projects". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Origin chat and bond with go-zero
The first contact with go-zero is the National Day holiday in October 2020. coincidentally, I saw someone in the go-micro group asking about go-zero. At that time, the author of go-zero probably answered in the group, which aroused my curiosity. The go-micro1.x used by the company at that time, because the go-micro version is really too chaotic, 2 is not understood by many people, and now there is a 3, and these major versions are highly incompatible, which is a mess. I went to github.com to check go-zero with curiosity, but I didn't give up because of its few star numbers and documents. Haha, I went to go get it with the mentality of trying to play. From then on, I discovered the New World, joined the go-zero group, and started the journey of go-zero.
Several reasons for choosing it
Microservices: in the current environment, there have been more and more criticisms about single services. After the project has grown up, the lessons of "pulling together and moving the whole body" can be found everywhere, maintenance is becoming more and more difficult, testing is also a headache, slow construction speed, and so on. Under this trend, embracing micro-services has become a major trend. Go-zero is a micro-service framework and can solve many pain points and difficulties encountered in many practical projects for me.
Stability: internal and external homology. Stability is very important to me, and their homology inside and outside the company is bound to ensure the stability of this framework.
High concurrency: during the 2020 epidemic, Dawn Blackboard easily gained support for the number of 10 million daily active users.
Productivity: when it comes to work efficiency, it must be mentioned that goctl,goctl with go-zero can basically generate all the code through this tool. You only need to care about your own business logic, including one-click generation of dockerfile,k8s yaml files, which is simply not too cool, which greatly improves the work efficiency.
Code quality: probably read some go-zero source code, the code quality still feel no spray, at least feel much better than my own writing, , this everyone's opinion is different, you can go to see for yourself.
Team: when I added go-zero author Wechat, I felt that he was very modest, no matter asked some basic things or some online practical experience, he would always patiently give me answers and opinions. During my use, I also mentioned some bug,go-zero team can solve in time, the iterative speed really amazed me. Everyone should know how difficult it is to open source in China.
Compare with other go micro-service frameworks: I have probably played go-micro, go-kit, kratos, rpcx, go-zero in go's micro-service framework.
Go-micro, I said from the beginning that the version was really a little confusing.
Go-kit is also good, but there is relatively little information.
Kratos has been leaked by bilibili's source code. Everyone should know about it. Some time ago, it was broken and almost euthanized. Mao Shen said in issue that he was too busy, but they are still looking forward to releasing version 2.0.
Rpcx didn't play much for a while, but they advertised that "good future" was also used. Go-zero means "good future". Haha.
I have already mentioned the above go-zero, so I won't mention it any more.
Design architecture
Before introducing the actual use of go-zero, let's talk about the overall architecture for easier understanding.
CI/CD
Step1: the local deveploer develops the code and then submits it to gitlab (here the branch will not elaborate)
Step2:jenkins, deployed using pipline
Pull the code from gitlab
Docker build, which builds the image based on code on the latest gitlab
Docker push, push the built image to the image repository (of course, you usually have your own private image repository, such as harbor, or you can use Aliyun)
Kubectl apply-f xxx.yaml: deploy to K8s using kubectl (Ali Cloud K8s container service is so easy to use, wouldn't it be a pity not to use it? )
After kubectl deployment, K8s will pull the latest image you just packaged from your image warehouse according to the image defined by yaml in your service. So~~ has been launched successfully!
Well, some students said that Aliyun K8s is easy to use, but I can't write or. I don't want to write Dockerfile. I don't want to write K8s yaml or. It doesn't matter. Goctl said let it go and let me do it.
Generate Dockerfile
$goctl docker-go user.go
Generate k8s yaml
$goctl kube deploy-name user-api-namespace blog-image user:v1-o user.yaml-port 2233
So, it's that simple.
Access proc
App/web/pc first accesses Aliyun's load balancer SLB through the firewall. At the same time, SLB can hide your backend server ip and prevent DDOS attacks. Although there is a limit, it is better than no ~ ~. Then SLB accesses the front nginx,nginx as a proxy, and the service in k8s is exposed through nodeport to proxy the service in nignx. At the same time, log is reported to kafka in nginx Then api can get multiple rpc nodes in etcd and call multiple back-end rpc services. Rpc is responsible for interacting with db, or calling other rpc to obtain data (of course, api and rpc are dynamically discovered through etcd). The data is returned to api,api, and then returned to the client layer by layer.
The overall architecture is highly available and highly available
Project design
Project address: https://github.com/Mikaelemmmm/gozerobasic
Go's projects are flexible, unlike java, which has formed a unified standardization, so the structure of different projects is different. My approach is as follows:
A large warehouse used for the whole project, under the fishtwo root directory of the project:
App: application internal program
Build: build, script, etc.
Lib: internal libraries used by applications
App is divided into three modules:
Gateway:api service
Services: rpc service
Jobs: daily tasks to be dealt with (this can be done using the go-zero author's go-queue, which is easy to use after testing. Haha, it will be written in later.)
This is the end of "how to migrate go-zero for Enterprise projects". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.