Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >gRPC rocks build your first gRPC service(part 1)

gRPC rocks build your first gRPC service(part 1)

作者头像
jimmyhzhao
发布于 2022-04-10 04:02:11
发布于 2022-04-10 04:02:11
23000
代码可运行
举报
文章被收录于专栏:SkemaloopSkemaloop
运行总次数:0
代码可运行

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
代码运行次数:0
运行
AI代码解释
复制
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 删除。

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

评论
登录后参与评论
暂无评论
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验