go-kit-micro-service
是基于项目go kit开发的微服务系统框架,集成了服务注册/服务发现/负载均衡/限流/断流/链路追踪等相关微服务治理的封装,可以通过插件protoc-gen-gokit-micro实现业务代码以及接口HTTP
+ GRPC
的自动生成,完成微服务应用的快速搭建。
-
服务注册与发现, 目前支持hashicorp consul服务注册与发现;
-
数据链路追踪, 目前支持openzipkin的链路追踪;
-
限流, 目前封装了uber-go ratelimit(基于漏斗)以及juju ratelimit(基于令牌桶)的限流封装;
-
日志,使用了sirupsen logrus;
依赖环境如下:
protobuf
protoc-gen-go
protoc-gen-go-grpc
protoc-gen-gprc-gateway
protoc-gen-openapiv2
protoc-gen-gokit-micro
$ sudo apt-get install autoconf automake libtool make g++
通过github
下载对应版本的protobuf
$ wget https://github.com/protocolbuffers/protobuf/releases/download/v21.5/protobuf-cpp-3.21.5.tar.gz
$ tar -xvf ./protobuf-cpp-3.21.5.tar.gz
protobuf-3.21.5/
protobuf-3.21.5/WORKSPACE
...
编译安装
$ cd protobuf-3.21.5/
protobuf-3.21.5 $ ./autogen.sh
protobuf-3.21.5 $ ./configure
protobuf-3.21.5 $ make
protobuf-3.21.5 $ sudo make install
protobuf-3.21.5 $ sudo ldconfig
$ go get -u github.com/golang/protobuf/protoc-gen-go
$ go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
$ go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
$ go install github.com/golang/protobuf/protoc-gen-go
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
$ go get -u github.com/leewckk/protoc-gen-gokit-micro
所有需要的prtoc
插件如下:
protobuf-3.21.5 $ ls ~/go/bin/ -alh | grep protoc
-rwxrwxr-x 1 liwenchao liwenchao 6.8M Aug 15 16:17 protoc-gen-go
-rwxrwxr-x 1 liwenchao liwenchao 6.7M Aug 15 16:17 protoc-gen-go-grpc
-rwxrwxr-x 1 liwenchao liwenchao 12M Aug 15 16:12 protoc-gen-gokit-micro
-rwxrwxr-x 1 liwenchao liwenchao 9.3M Aug 15 16:15 protoc-gen-grpc-gateway
-rwxrwxr-x 1 liwenchao liwenchao 9.9M Aug 15 16:15 protoc-gen-openapiv2
go-kit-micro-service-template,是go-kit-micro-service使用的参考模板,使用方法如下:
$ git clone https://github.com/leewckk/go-kit-micro-service-template.git
假设项目名称为一个处理订单的业务,项目名称service-bill
go-kit-micro-service-template git:(master) $ ./init.sh service-bill