• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript grpc.load函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript grpc.credentials类代码示例发布时间:2022-05-25
下一篇:
TypeScript groupby-api.Pager类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap