kubernetes - Google Cloud Endpoints (ESP) gRPC 转码为驼峰式
问题描述
我已按照此处的说明使用 Google Cloud Endpoints / ESP 部署了 gRPC 服务器:
https://cloud.google.com/endpoints/docs/grpc/get-started-kubernetes-engine
在我的 proto 文件中,我的字段按照 Protocol Buffers 命名约定 ( https://developers.google.com/protocol-buffers/docs/style#message-and-field-names ) 以 snake_case 命名,如下所示:
message MyMessage {
string my_field = 1;
}
部署到 Cloud Endpoints 时,字段名称将转换为 camelCase。因此,如果我使用 HTTP 端点调用 API,JSON 响应如下所示:
{
"myField":"field value"
}
如果我使用 GRPC 客户端 (Node.js) 调用服务,则会以原始格式返回响应对象:
{
"my_field":"field value"
}
在 Cloud Endpoints Developer Portal 文档中,字段名称也会转换为驼峰式。
在替换现有 API 时,我更喜欢对 GRPC 和 HTTP 客户端使用蛇形案例。如果我可以防止字段名称被转换,我基本上可以将后端切换到新服务,而无需对客户端进行任何更改。
有没有办法强制 ESP 在转码为 HTTP/JSON 时使用驼峰式字段名称?
解决方案
我正在使用 ESP 将我的 grpc 应用程序部署到 k8s 中,下面的配置会将 protobuf 响应转码为蛇案例而不是骆驼案例
- name: esp
image: gcr.io/endpoints-release/endpoints-runtime:1
imagePullPolicy: Always
args: [
"--http_port=9000",
"--backend=grpc://127.0.0.1:8080",
"--service=xxxxxx",
"--version=xxxxxx",
"--transcoding_preserve_proto_field_names",
"--transcoding_always_print_primitive_fields"
]
ports:
- name: http
containerPort: 9000
推荐阅读
- python - 在 Python 中迭代列表并找到合适的字符串模式的最快(最有效)方法是什么?
- javascript - Javascript 错误 appendChild 不是函数
- javascript - 关闭窗口前的提示信息
- excel - 如何使用存储在 Variant 变量中的 Range 进行复制和粘贴?
- django - 将 ParentalKey 链接到 Wagtail 中的抽象类和所有子类
- flutter - 为什么 IconButtons 之间的空间没有填满?
- python - 如何在python中打印所有可能的不同长度的排列?
- sql-server - 插入后更新触发器触发
- docker - 为什么我无法在本地启动带有图像 nginxphp 的容器
- c# - 在 asp net core web appllication 中运行 powershell 7 脚本