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 Serverhttps://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.jsconst 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濡備綍鍚敤鍘嬬缉的主要内容,如果未能解决你的问题,请参考以下文章

濡備綍鍚戜竴涓洓宀佸皬瀛╄В閲婂姩鎬佽鍒掞紵

linux鍘嬬缉瑙e帇鏂囦欢

[鎵撳寘浼樺寲]Webpack浣撶Н鍘嬬缉

Asp.Net浣跨敤Yahoo.Yui.Compressor.dll鍘嬬缉Js|Css

centos7绯荤粺涓嬪畨瑁卲hp-fpm骞堕厤缃畁ginx鏀寔骞跺紑鍚綉绔檊zip鍘嬬缉

鍐呮牳妯″潡鍙傛暟璁捐