GRPC and go chassis
Although GRPC-Go itself has some cloud native capabilities, such as load balancing, but it is far from enough, and users need to write their own code to achieve.
Go Chassis is a unified microservice development framework that can integrate different communication protocols and use unified functions such as route management, load balancing, fuse downgrading, traffic limiting, and monitoring.
With the popularity of GRPC, Go Chassis decided to integrate GRPC into its framework, bringing richer and more powerful features to GRPC-Go
You can start to understand the capabilities provided by Go Chassis from this article.
Go Language Microservices development framework practice – Go Chassis
The principle of
Go Chassis is designed to allow access to any protocol
Can you access the Go Chassis framework by implementing the client and Server interface regardless of the protocol
https://github.com/go-chassis/go-chassis/blob/master/core/client/client.go
https://github.com/go-chassis/go-chassis/blob/master/core/server/server.go
Each request is translated to a uniform abstract Invocation, which is the standard model in microservice governance, so standard features such as load balancing, fuse, route management, etc., can be used to send the request out again using the standard protocol, which is fully compatible with the native protocol.
example
GRPC program written using the go chassis need to follow certain standards, is not the same as the primary method of writing, the complete examples at https://github.com/go-chassis/go-chassis-examples/tree/master/grpc
The Apache ServiceComb Service Center is used as the registry
Write the proto IDL
1. Write proto description files
Go chassis contains the concepts of Schema and operation: HelloWorld.Greeter is schema and SayHello is operation
2. Generate the helloworld. Pb. Go
Protoc – go_out =. The helloworld. Proto
The next steps are different from the original GRPC-Go
3. Manually change a variable in helloWorld.pb. go
You must change _Greeter_serviceDesc to Greeter_serviceDesc
The Provider side
1. Write business logic
2. Register the business logic with the Go Chassis, and the variable Greeter_serviceDesc needs to be changed
The first parameter indicates which protocol server you want to register with, the second is the business logic, and the third is GRPC Serivce DESC
3. Modify the chassis.yaml configuration file. The minimum configuration item requires configuring the service center and specifying the protocol server to be started
4. Modify microservice.yaml to give the microservice a name
5. Start the service
The Consumer end
1. Get the PB file and generate the GO code
Protoc – go_out =. Hello. Proto
2. Modify the chassis.yaml configuration file
3. Modify microservice.yaml to name consumer
4. Call the server in main, specify the micro service name (RPCServer), schema, operation and parameters and return
Now that GRPC has the basic load balancing capability, the server registers with Service Center
The Consumer periodically caches the list of Provider instances for load balancing
For more advanced features, see the documentation
http://go-chassis.readthedocs.io/en/latest/