前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >gRPC rocks build your first gRPC service(part 1)

gRPC rocks build your first gRPC service(part 1)

作者头像
jimmyhzhao
发布2022-04-10 12:02:11
2030
发布2022-04-10 12:02:11
举报
文章被收录于专栏:SkemaloopSkemaloop

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.

How gRPC works

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.

  1. create schema, which will be defined in protobuf.
  2. generate server and stub.
  3. add your business logic and start the service.

Create Schema

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.

代码语言:javascript
复制
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.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-04-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • How gRPC works
  • Create Schema
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档