本文整理汇总了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;
}
示例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.
//
示例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
};
示例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;