SHARE
TWEET

Untitled

a guest Aug 17th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var PROTO_PATH = __dirname + '/calculator.proto';
  2.  
  3. var grpc = require('grpc');
  4. var protoLoader = require('@grpc/proto-loader');
  5. var packageDefinition = protoLoader.loadSync(
  6.     PROTO_PATH,
  7.     {
  8.         keepCase: true,
  9.         longs: String,
  10.         enums: String,
  11.         defaults: true,
  12.         oneofs: true
  13.     });
  14. var calculator = grpc.loadPackageDefinition(packageDefinition).calculator;
  15.  
  16. function multiply(call, callback) {
  17.     let multiplicationResult = call.request.num1 * call.request.num2;
  18.     callback(
  19.         null,
  20.         { result: multiplicationResult }
  21.     );
  22. }
  23.  
  24. /*
  25. Starts an RPC server that receives requests for the Calculator service
  26. */
  27. function main() {
  28.     var server = new grpc.Server();
  29.     server.addService(
  30.         calculator.CalculatorService.service,
  31.         { multiply: multiply }
  32.     );
  33.     server.bind(
  34.         '0.0.0.0:50051',
  35.         grpc.ServerCredentials.createInsecure()
  36.     );
  37.     server.start();
  38. }
  39.  
  40. main();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top