If you are a beginner, you must have been frustrated by the complexity of using protoc to build a gRPC service. The protoc compiler is powerful, but not newbee friendly. In this series of articles, I will explain how I build gRPC services in a toolkit called Skemaloop, in which you will find that building a gRPC service is quite easy.
First, let me introduce the concepts of how gRPC works.
The gRPC framework provides a mechnism, in which the IDL(Interface Definition Language) can be used to define the service interface and messge types. The IDL will be used to seralize and deseralize the messages between server and clients. Developers can use protoc compiler to generate gRPC Server and gRPC Stub code boilerplate, and all the communciations are handled by the auto-generated code of the gRPC framework. There are many articles to introduce gRPC framework and the IDL of protobuf, I don`t want to cover the details here.
There are three steps to generate a gRPC server.
The offical site of Skemaloop provides the full process that you can follow to start your work. Click the try now button to start your journey.
You need login with your github account. After you login, you can start define your application interface.
The group is your github`s user account. You can create a new repository for the schema defintions, I will use my sandbox repository for this tutorial. If you want to create a hierachy you can define your path. I will leave to the default now.
The module and package is the hierachy of your schema, each module has multiple packages, and each packages have multiple serviecs definitions, in our case, multiple protobuf files.
I will call my service to SayHi.
Let`s create schema and continue. A schema definition is created as below.
syntax = "proto3";
//package code generated by schemakit DO NOT EDIT.
package sample_module.sample_package;
message HelloRequest {
string msg = 1;
}
message HelloReply {
string msg = 1;
string code = 2;
}
service SayHi {
rpc SayHello (HelloRequest) returns (HelloReply);
}
In next articile, I will explain the steps of how to create the server and stub code, and start the service.
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有