load: Loads and parses the .proto file you uploaded.connect: Establishes a connection with the gRPC server.invoke: Initiates an RPC call and obtains the response.close: Closes a connection.// 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();// Load the addsvc.proto file from the root directory of the protocol file.client.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();};
Feedback