NodeJS gRPC濡備綍鍚敤鍘嬬缉
Posted 绋嬪簭涓変簲杈?/a> No
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NodeJS gRPC濡備綍鍚敤鍘嬬缉相关的知识,希望对你有一定的参考价值。
鍦∟ode椤圭洰閲岃皟鐢╣RPC鏃讹紝鍙戠幇榛樿娌℃湁鍚敤gzip鍘嬬缉锛岄鐨勭杩欒兘蹇嶐煒侊紵鍡栧棖瀵荤珷鎽樺彞鑰侀洉铏紝璋风涔熸病鎵惧埌锛屽拫鍔炲憿锛?/p>
鎵嬫捀婧愮爜浜嗭紝鍝庯紝鎷斿墤鍥涢【蹇冭尗鐒?..... 娴烽噺娴烽噺 鍋剁劧鍙戠幇Node鐗堟湰鐨刧RPC 瀹㈡埛绔殑UA鏄細
grpc-node/1.24.2 grpc-c/8.0.0 (osx; chttp2; ganges)
鐪嬫潵鍍忔槸鍖呰浜咰璇█鐗堟湰gRPC鐨勫鎴风锛屽彂鐜颁唬鐮侀噷纭疄鏄敤鐨?/p>
C-based Client and Server
https://github.com/grpc/grpc-node
浜庢槸鎵惧埌C浠g爜锛屾壘鍒颁簡瑙e喅鏂规,鍏蜂綋浠g爜鍦ㄨ繖閲岋細
https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/compression_types.h
typedef enum {
GRPC_COMPRESS_NONE = 0,
GRPC_COMPRESS_DEFLATE,
GRPC_COMPRESS_GZIP,
/* EXPERIMENTAL: Stream compression is currently experimental. */
GRPC_COMPRESS_STREAM_GZIP,
/* TODO(ctiller): snappy */
GRPC_COMPRESS_ALGORITHMS_COUNT
} grpc_compression_algorithm;
typedef enum {
GRPC_COMPRESS_LEVEL_NONE = 0,
GRPC_COMPRESS_LEVEL_LOW,
GRPC_COMPRESS_LEVEL_MED,
GRPC_COMPRESS_LEVEL_HIGH,
GRPC_COMPRESS_LEVEL_COUNT
} grpc_compression_level;
鍥犱负鎴戠敤鐨刧zip锛屽湪鍒涘缓gRPC瀹㈡埛绔椂浼犲叆涓や釜鍙橀噺锛?/span>
'grpc.default_compression_algorithm': 2,
'grpc.default_compression_level': 2
Node浠g爜瀹屾暣濡備笅锛?br>
const values = [208402197];
const version ='1.1.0';
const request = {
interfaceName:'com.example.PersonServiceApi',
version: version,
//group :'',
method:'getOne',
types :['long'],
values:JSON.stringify(values)
};
const PROTO_PATH = __dirname + '/clazz_method_param.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 dubbo = grpc.loadPackageDefinition(packageDefinition).dubbo;
// https://github.com/grpc/grpc/blob/master/examples/node/dynamic_codegen/greeter_client.js
const client = new dubbo.ProxyService('grpc.internal.example.com:5050',
grpc.credentials.createInsecure(), {
'grpc.default_compression_algorithm': 2,
'grpc.default_compression_level': 2
});
client.InvokeProxy(request, function(err, response) {
console.log('result:', response);
});
鎵撳畬鏀跺伐蹇箰鍘荤潯瑙変簡銆?br>
以上是关于NodeJS gRPC濡備綍鍚敤鍘嬬缉的主要内容,如果未能解决你的问题,请参考以下文章
Asp.Net浣跨敤Yahoo.Yui.Compressor.dll鍘嬬缉Js|Css