gRPC (NodeJS)

Github地址(Nodejs 版本):GitHub - justajwolf/GrpcDemo

一、编写pb文件(.proto),例:chat.proto

  注:1.protocol buffers 维基百科:https://zh.wikipedia.org/wiki/Protocol_Buffers

    2.protocol buffers 语法详见:https://developers.google.com/protocol-buffers

syntax = "proto3";  // 使用proto3语法,因为从3.0.0 Beta2版,开始支持JavaScript

package grpcTest;   // 定义包名
// 定义服务名
service chat {
  // 定义远程调用方法
  rpc getMessage(HelloRequest) returns (HelloResponse) {}
  rpc getAge(HelloRequest) returns (HelloResponse) {}
}

// 定义消息类型
message HelloRequest{
  int32 id = 1;
  string name = 2;
  int32 age = 3;
  string year = 4;
}

// 定义消息类型
message HelloResponse{
  string reply = 1;
}

二、demo代码:index.js

const path = require('path');
const grpc = require(
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值