當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript grpc.load函數代碼示例

本文整理匯總了TypeScript中grpc.load函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript load函數的具體用法?TypeScript load怎麽用?TypeScript load使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了load函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

  /**
   * Server is a gRPC transport provider for serving.
   *
   * @param {Object} config Configuration object.
   * Requires properties:addr,package,proto,service
   * Optional properties: credentials.ssl.certs
   */
  constructor(config: any, logger: any) {
    if (_.isNil(logger)) {
      throw new Error('gRPC server transport provider requires a logger');
    }
    if (!_.has(config, 'addr')) {
      throw new Error('server is missing addr config field');
    }
    if (!_.has(config, 'services')) {
      throw new Error('server is missing services config field');
    }
    this.config = config;
    this.logger = logger;

    // console['error'] = logger.debug;
    // gRPC logger
    grpc.setLogger(console);

    this.server = new grpc.Server();

    // build protobuf
    const protoRoot = config.protoRoot || path.join(process.cwd(), 'protos');
    if (_.isNil(protoRoot) || _.size(protoRoot) === 0) {
      throw new Error('config value protoRoot is not set');
    }
    const protos = config.protos;
    if (_.isNil(protos) || _.size(protos) === 0) {
      throw new Error('config value protos is not set');
    }
    this.logger.verbose(`gRPC Server loading protobuf files from root ${protoRoot}`,  { protos });


    const proto = [];
    for (let i = 0; i < protos.length; i++) {
      const filePath = { root: protoRoot, file: protos[i] };
      this.proto = grpc.load(filePath, 'proto', {
        longsAsStrings: false
      });
      proto[i] = this.proto;
    }

    let k = 0;
    this.service = _.transform(this.config.services, (service: any, protobufServiceName: string, serviceName: string) => {
      const serviceDef = _.get(proto[k], protobufServiceName);
      if (_.isNil(serviceDef)) {
        throw new Error(`Could not find ${protobufServiceName} protobuf service`);
      }
      _.set(service, serviceName, serviceDef.service);
      k++;
      logger.verbose('gRPC service loaded', serviceName);
    });
    this.name = NAME;
  }
開發者ID:restorecommerce,項目名稱:chassis-srv,代碼行數:59,代碼來源:index.ts

示例2: require

var zlib = require("zlib");

var debugModule = require('debug');
let debug = debugModule('hfc'); // 'hfc' stands for 'HyperLedger Fabric Client'

//
// Load required crypto stuff.
//

var sha3_256 = require('js-sha3').sha3_256;

//
// Load required protobufs.
//

var _timeStampProto = grpc.load(__dirname + "/protos/google/protobuf/timestamp.proto").google.protobuf.Timestamp;

//
// GenerateUUID returns an RFC4122 compliant UUID.
// http://www.ietf.org/rfc/rfc4122.txt
//

export function GenerateUUID() {
  return uuid.v4();
};

//
// GenerateTimestamp returns the current time in the google/protobuf/timestamp.proto
// structure.
//
開發者ID:285452612,項目名稱:fabric,代碼行數:30,代碼來源:sdk_util.ts

示例3: require

"use strict";
/**
 * @fileOverview This file serves as the interface for communicating with
 *     the slack microservice. It responds to chatEventEmitter events
 *     emitted in the lifecylce of a conversation.
 *
 * NOTE(dharness): This file is under active development and its interface
 *     is subject to breaking changes.
 */
var chatEventEmitter = require('services/ChatEventEmitter.js');
var grpc = require('grpc');
var path = require('path');


var PROTO_PATH = path.resolve(__dirname, '../../protos/slack.proto');
var slack = grpc.load(PROTO_PATH).slack;


function main() {

  let dispatch = new slack.Dispatch('slack:50051', grpc.credentials.createInsecure());

  chatEventEmitter.on('INCOMING_MESSAGE', () => {
    // console.log('SLACK SERVICE INCOMING_MESSAGE');
  });

  chatEventEmitter.on('NEW_CONVERSATION', (channelRequest) => {
    var name = channelRequest.channel_name.toString()
    let channelRequest2 = {
      channel_name: name
    };
開發者ID:sirbabelot,項目名稱:babelot-server,代碼行數:31,代碼來源:index.ts

示例4: require

/**
 * @fileoverview This file is responsible for creating the remote connection
 *     with the chatterpiller service in the form of an RPC stream.
 */
"use strict";
var chatEventEmitter = require('services/ChatEventEmitter.js');
var EVENTS = require('services/ChatEvents.js');
var grpc = require('grpc');
var path = require('path');


var PROTO_PATH = path.resolve(__dirname, '../../protos/messages.proto');
var messages = grpc.load(PROTO_PATH).messages;
var dispatch = new messages.Dispatch('chatterpillar:50052',
    grpc.credentials.createInsecure());

var stream = dispatch.startConversation();

module.exports = stream;
開發者ID:sirbabelot,項目名稱:babelot-server,代碼行數:19,代碼來源:grpcClient.ts


注:本文中的grpc.load函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。