如何解决"Decompressor is not installed for grpc-encoding"问题?



当我从Dart:调用我的gRPC Golang服务器时,我收到了这个错误

捕获错误:gRPC错误(代码:12,代码名:UNIMPLEMENTED,消息:gRPC:解压缩器未安装用于gRPC编码的"gzip",详细信息:[],rawResponse:null,尾部:{}(

我读过https://github.com/bradleyjkemp/grpc-tools/issues/19,这似乎不适用于我的问题。

服务器在Gcloud Ubuntu上运行1.19.2。Dart在Mac Monterey 上运行2.18.2

我有一个叫Go服务器的Dart客户端。两者似乎都在使用GZIP进行压缩。

Dart原型

syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}

GO原型:

syntax = "proto3";
option go_package = "google.golang.org/grpc/examples/helloworld/helloworld";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}

Dart客户端代码:

import 'package:grpc/grpc.dart';
import 'package:helloworld/src/generated/helloworld.pbgrpc.dart';
Future<void> main(List<String> args) async {
final channel = ClientChannel(
'ps-dev1.savup.com',
port: 54320,
options: ChannelOptions(
credentials: ChannelCredentials.insecure(),
codecRegistry:
CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
),
);
final stub = GreeterClient(channel);
final name = args.isNotEmpty ? args[0] : 'world';
try {
final response = await stub.sayHello(
HelloRequest()..name = name,
options: CallOptions(compression: const GzipCodec()),
);
print('Greeter client received: ${response.message}');
} catch (e) {
print('Caught error: $e');
}
await channel.shutdown();
}

Go gRPC服务器与Go gRPC客户端和BloomRPC配合使用效果良好。

一般来说,我是gRPC的新手,也是Dart的新手。

提前感谢您为解决此问题提供的任何帮助。

您共享的错误表明您的服务器不支持gzip压缩。

最快的修复方法是在客户端的调用选项中不使用gzip压缩,方法是删除以下行:

options: CallOptions(compression: const GzipCodec()),

从你的飞镖代码。

go-grpc库在包github.com/grpc/grpc-go/encoding/gzip中实现了gzip压缩编码,但这是实验性的,因此在生产中使用它可能不明智;或者至少你应该密切关注它:

// Package gzip implements and registers the gzip compressor
// during the initialization.
//
// Experimental
//
// Notice: This package is EXPERIMENTAL and may be changed or removed in a
// later release.

如果你想在你的服务器上使用它,你只需要导入包;包中没有面向用户的代码:

import (
_ "github.com/grpc/grpc-go/encoding/gzip"
)

关于grpc-go压缩的文档提到了上面的包,作为如何实现这样一个压缩器的示例

因此,您可能还想将代码复制到一个更稳定的位置,并负责自己维护它,直到有一个稳定的支持版本。

相关内容

最新更新