解决问题:如何安装 grpc 编码解压缩器?
来源:stackoverflow
时间:2024-02-06 10:51:23 324浏览 收藏
今天golang学习网给大家带来了《解决问题:如何安装 grpc 编码解压缩器?》,其中涉及到的知识点包括等等,无论你是小白还是老手,都适合看一看哦~有好的建议也欢迎大家在评论留言,若是看完有所收获,也希望大家能多多点赞支持呀!一起加油学习~
当我从 dart 调用 grpc golang 服务器时收到此错误:
捕获错误:grpc 错误(代码:12,codename:unimplmented,消息:grpc:未安装 grpc 编码“gzip”的解压缩器,详细信息:[],rawresponse:null,预告片:{})
我已阅读 https://github.com/bradleyjkemp/grpc-tools/issues/19,它似乎不适用于我的问题。
服务器在 gcloud ubuntu 上运行 1.19.2。 dart 在 mac monterey 上运行 2.18.2
我有一个 dart 客户端调用 go 服务器。两者似乎都使用 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'; Futuremain(List 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()),
来自您的 dart 代码。
go-grpc 库在 package 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" )
documentation about compression for grpc-go 提到上述包作为如何实现此类压缩器的示例。
因此,您可能还想将代码复制到更稳定的位置,并自行负责维护它,直到有稳定的受支持版本为止。
文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《解决问题:如何安装 grpc 编码解压缩器?》文章吧,也可关注golang学习网公众号了解相关技术文章。
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
139 收藏
-
204 收藏
-
325 收藏
-
477 收藏
-
486 收藏
-
439 收藏
-
357 收藏
-
352 收藏
-
101 收藏
-
440 收藏
-
212 收藏
-
143 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习