如何解决“没有为 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 进行压缩。


飞镖原型


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;

}

去原型:


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;

}

飞镖客户端代码:


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()]),

    ),

  );

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


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


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


慕虎7371278
浏览 158回答 1
1回答

一只萌萌小番薯

您分享的错误表明您的服务器不支持 gzip 压缩。最快的解决方法是在客户端的调用选项中不使用 gzip 压缩,方法是删除以下行:options: CallOptions(compression: const GzipCodec()),从你的飞镖代码。go-grpc 库在packagegithub.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 (&nbsp; &nbsp; _ "github.com/grpc/grpc-go/encoding/gzip")关于 grpc-go 压缩的文档提到了上面的这个包作为你如何实现这样一个压缩器的例子。因此,您可能还想将代码复制到更稳定的位置并自行负责维护它,直到有稳定的受支持版本为止。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go