How to use the grpc.loadPackageDefinition function in grpc

To help you get started, we’ve selected a few grpc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GoogleCloudPlatform / esp-v2 / tests / clients / agent_client.js View on Github external
var grpc = require('grpc');
var protoLoader = require('@grpc/proto-loader');

var PROTO_PATH = __dirname + '/../../api/agent/agent_service.proto';
var packageDefinition = protoLoader.loadSync(
  PROTO_PATH, {
    keepCase: true,
    longs: String,
    enums: String,
    defaults: true,
    oneofs: true,
    // includeDirs: [__dirname + '/proto/protobuf', __dirname + '/proto/googleapis'],
  });

var agent_proto = grpc.loadPackageDefinition(packageDefinition).google.api_proxy.agent;

var client = new agent_proto.AgentService('localhost:8790',
  grpc.credentials.createInsecure());


client.GetAccessToken({}, undefined, function(err, res) {
  if (err) {
    console.log("Error: ", err);
  } else {
    console.log("Result: ", res);
  }
});
github moorara / microservices-demo / services / graphql / src / grpc / index.js View on Github external
const path = require('path')
const grpc = require('grpc')
const protoLoader = require('@grpc/proto-loader')

const PROTO_PATH = path.join(__dirname, '../grpc/switch.proto')

// https://grpc.io/docs/tutorials/basic/node.html
// https://www.npmjs.com/package/@grpc/proto-loader
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: false, // true preserves field names and false changes them to camelCase
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
})
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition)
const proto = protoDescriptor.proto

module.exports = { proto }
github googleapis / nodejs-storage / bin / benchwrapper.js View on Github external
description: 'The port that the Node.js benchwrapper should run on.',
    type: 'number',
    demand: true,
  })
  .parse();

const PROTO_PATH = __dirname + '/storage.proto';
// Suggested options for similarity to existing grpc.load behavior.
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
});
const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
const storageBenchWrapper = protoDescriptor.storage_bench;

const storageClient = new Storage();

function read(call, callback) {
  const bucketName = call.request.bucketName;
  const objectName = call.request.objectName;

  storageClient
    .bucket(bucketName)
    .file(objectName)
    .download({validation: false});

  callback(null, null);
}
github prisma / prisma-examples / node / grpc / client / post.js View on Github external
const PROTO_PATH = __dirname + '/../service.proto'

const grpc = require('grpc')
const protoLoader = require('@grpc/proto-loader')
const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true,
})
const blog = grpc.loadPackageDefinition(packageDefinition).blog

function main() {
  const client = new blog.Blog(
    'localhost:50051',
    grpc.credentials.createInsecure(),
  )

  const id = ''
  client.post({ id }, (err, response) => {
    if (err) {
      console.error(err)
      return
    }
    console.log(response)
  })
}
github strongloop / loopback-connector-grpc / lib / grpc-connector.js View on Github external
process.nextTick(function() {
      cb(new Error('No grpc specification provided'));
    });
    return;
  }

  debug('Loading proto file: %s', self.spec);
  const pkgDef = protoLoader.loadSync(self.spec, {
    keepCase: true,
    longs: String,
    enums: String,
    defaults: true,
    oneofs: true,
  });

  self.proto = grpc.loadPackageDefinition(pkgDef);

  const services = utils.discoverServices(this.proto);
  const host = this.settings.host || this.settings.hostname || 'localhost';
  const port = this.settings.port || 50051;
  const url = this.settings.url || (host + ':' + port);

  let credentials;
  if (typeof this.settings.security === 'object' &&
    this.settings.security != null) {
    const rootCerts = fs.readFileSync(this.settings.security.rootCerts);
    const key = this.settings.security.key &&
      fs.readFileSync(this.settings.security.key);
    const cert = this.settings.security.cert &&
      fs.readFileSync(this.settings.security.cert);
    credentials = grpc.credentials.createSsl(rootCerts, key, cert);
  } else {
github muninrpc / muninrpc / app / lib / local / grpc-client.ts View on Github external
const path = require('path');
const PROTO_PATH = path.resolve(__dirname, '../protos/todo.proto');
const grpc = require('grpc');
const async = require('async');

const protoLoader = require('@grpc/proto-loader');

const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
});

const todo = grpc.loadPackageDefinition(packageDefinition).todo;

const client = new todo.ListActions(
  'localhost:50052',
  grpc.credentials.createInsecure()
);

/**
 *
 * @param {function} cb called to perform actions using the list data
 */

module.exports = {
  runGetList: res => {
    client.GetList({}, (err, list) => {
      if (err) {
        throw err;
github GoogleCloudPlatform / cloud-ops-sandbox / src / paymentservice / server.js View on Github external
loadProto (path) {
    const packageDefinition = protoLoader.loadSync(
      path,
      {
        keepCase: true,
        longs: String,
        enums: String,
        defaults: true,
        oneofs: true
      }
    );
    return grpc.loadPackageDefinition(packageDefinition);
  }
github rsbondi / nodes-debug / .nodetypes / src / lnd / LndController.js View on Github external
callback(null, metadata);
        });
        
        const lndCert = fs.readFileSync(this._config.certPath);
        const sslCreds = grpc.credentials.createSsl(lndCert);
        
        const credentials = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
        
        const packageDefinition = protoLoader.loadSync(`${__dirname}/rpc.proto`,{keepCase: true,
            longs: String,
            enums: String,
            defaults: true,
            oneofs: true
           });

        let lnrpcDescriptor = grpc.loadPackageDefinition(packageDefinition);
        
        const lnrpc = lnrpcDescriptor.lnrpc;
        const instance = new lnrpc.Lightning(`${this._config.host}:${this._config.port}`, credentials);

        lnrpcDescriptor = grpc.loadPackageDefinition(packageDefinition);
        const wlnrpc = lnrpcDescriptor.lnrpc;
        const winstance = new wlnrpc.WalletUnlocker(`${this._config.host}:${this._config.port}`, sslCreds);

        this.noservice = false
        return {Lightning: instance, WalletUnlocker: winstance}
    
    }