码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • gPRC入门笔记


    This blog is about learning gRPC
    You are welcomed to chat about it and if you like this blog, do not forget to give me a like.
    
    • 1
    • 2

    Welcome to see my homepage and contact me: NicholasYe’s Homepage.


    0. Before study

    • All the information comes from gRPC website, and I strongly recommend you to read it by yourself.
      • Introduction to gRPC
      • Quick start
      • Basic tutorail

    1. Introduction

    1. An overview
      • gRPC is a kind of tool which you can create a server and many client, while the server handle every call of the client and respond them.
      • You can easily create your server in Java with client in Go, Python and so on, which is a huge advantage.
      • gRPC use protocol buffers to transmit the message.

    2. What is protocol buffers?

    1. Introduction

      • Protocol buffers provide a language-neutral, platform-neutral, extensible mechanism for serializing structured data in a forward-compatible and backward-compatible way.
      • It’s like JSON, except it’s smaller and faster, and it generates native language bindings.
    2. Workflow:
      图片.png

    3. A very simple example

      1. In .proto definition, use Java to write down:
        message Person {
          optional string name = 1;
          optional int32 id = 2;
          optional string email = 3;
        }
        
        • 1
        • 2
        • 3
        • 4
        • 5
      2. After compiling this, you will get a Builder class:
        Person john = Person.newBuilder()
            .setId(1234)
            .setName("John Doe")
            .setEmail("jdoe@example.com")
            .build();
        output = new FileOutputStream(args[0]);
        john.writeTo(output);
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
      3. Then you can deserialize the data and use the methods protocol buffers creates in other languages, like C++:
        Person john;
        fstream input(argv[1], ios::in | ios::binary);
        john.ParseFromIstream(&input);
        int id = john.id();
        std::string name = john.name();
        std::string email = john.email();
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6

    3. Core concept

    1. In this section I will show you an simple but complete gPRC service, and explain what they mean:

      service HelloService {
        rpc SayHello (HelloRequest) returns (HelloResponse);
      }
      
      message HelloRequest {
        string greeting = 1;
      }
      
      message HelloResponse {
        string reply = 1;
      }
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • service: Define what your server want to receive and what to reply according to the message.
      • message: Define every message detail information.
    2. gPRC let you define four kinds of service method(you can also see the website for more detailed information):

      1. rpc SayHello(HelloRequest) returns (HelloResponse);
      2. rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse);
      3. rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse);
      4. rpc BidiHello(stream HelloRequest) returns (stream HelloResponse);

    4. A guidance of gPRC in python

    • See the website by yourself~

    Please clearly mark the source of the article in the process of reproducing it! Respect for originality and intellectual property rights, thanks!

  • 相关阅读:
    618快到了送上自制前端小项目(html css js)
    【运维心得】windows11安装mysql8解压版
    Git--本地仓库
    跨境电商为什么要用海外CN2云服务器?CN2云服务器是什么意思?
    Day712. 封闭类-Java8后最重要新特性
    【分享】围绕 API 团队协作与自动化测试的实践!
    实战 | 基于卷积神经网络的蘑菇识别微信小程序
    Electron App 安装包定制 -- Inno Setup 脚本 Pascal Scripting 初探
    python 爬取文章并保存为pdf
    三、W5100S/W5500+RP2040树莓派Pico<TCP Client数据回环测试>
  • 原文地址:https://blog.csdn.net/NicholasYTZ/article/details/125888366
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号