The asynchronous RPC framework based on the protobuf protocol includes the interfaces of various components.It implements service registration, discovery, current limiting, and circuit breaking.The most important thing is that it can be developed secondary and expanded better.
It can be expanded further and combined into a super application as follows.
Use polaris as the service registration center and management center. polaris. The entire RPC service framework relies on Polaris, which serves as a route between services and is also used to provide service information.
docker run -d --privileged=true -p 15010:15010 -p 8101:8101 -p 8100:8100 -p 8080:8080 -p 8090:8090 -p 8091:8091 -p 8093:8093 -p 8761:8761 -p 8848:8848 -p 9848:9848 -p 9090:9090 -p 9091:9091 polarismesh/polaris-standalone:latest
You can also use your own service management and implement the corresponding interface to use custom service registration and discovery.
type IRegistry interface {
Provider(*node)
Consumer()
Register(string, string)
Destroy()
GetNode(context.Context, string, string) (NodeInstance, error)
Limiter(context.Context, string) error
}
Use grafana to monitor the framework service nodes and track the status. Report monitoring information by Kafka.
docker run -d --name=grafana -p 3000:3000 grafana/grafana-enterprise
Subscribe to the monitoring information of each service from Kafka, report the monitoring information to Promethums, and check the monitoring status of each node and interface.
The framework protocol uses protobuf. Once the .proto file is defined, the corresponding protocol file and service interface can be generated with one click.To generate protocols and interfaces, we rely on the following tools.
- protoc [mac: brew install protobuf]
- protoc-gen-gofast
- protoc-gen-micro
syntax = "proto3";
package protocol;
message Request {
string username = 1;
string telephone = 2;
string email = 3;
}
message Response {
int32 Code = 1;
string msg = 2;
map<string,string> extra = 3;
}
service XXXService {
rpc XxxCall(Request) returns (Response) {}
}
protoc -I. --gofast_out=. --micro_out=. xxx.proto
xxx.proto struct and interface define
xxx.pb.go Generate Service interface struct
xxx.pb.micro.go Generate Service interface implement, client, server
-
Protocol Generation
Define the .proto file and use the tool to generate the protocol file. -
Server implement
The rpc service mainly implements the interface defined by proto.
Performance analysis can be achieved using the Pprof method under tools, which can generate the corresponding function call graph and Firefox graph.How to use it:
package main
import (
...
"github.com/shockerjue/gffg/tools"
)
func main() {
...
// Asynchronous Execution
tools.PProf()
...
return
}
You can execute the following command to collect data. After collecting data, you can access the performance indicator data through http://127.0.0.1:7778.
go tool pprof -http=:7778 -seconds=20 http://localhost:7777/debug/pprof/profile