产品动态
load:加载并解析您上传的 proto 文件。connect:与 gRPC 服务器建立连接。invoke:发起 RPC 调用并获得响应。close:关闭连接。// based on https://github.com/go-kit/kit/blob/master/examples/addsvc/pb/addsvc.protosyntax = "proto3";package addsvc;// The Add service definition.service Add {// Sums two integers.rpc Sum (SumRequest) returns (SumReply) {}}// The sum request contains two parameters.message SumRequest {int64 a = 1;int64 b = 2;}// The sum response contains the result of the calculation.message SumReply {int64 v = 1;string err = 2;}
// GRPC APIimport grpc from 'pts/grpc';const client = new grpc.Client();// 加载协议文件根目录中的 addsvc.protoclient.load([], 'addsvc.proto');export default () => {client.connect('grpcb.in:9000', { insecure: true });const rsp = client.invoke('addsvc.Add/Sum', {a: 1,b: 2,});console.log(rsp.data.v); // 3client.close();};
文档反馈