-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gRPC 转 Rest 的几种实现 #1
Comments
Envoy Filter gRPC-JSON Transcoder Demo: apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: myapp-grpc-transcoder
spec:
workloadSelector:
labels:
app: myapp # match your deployment
configPatches:
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
filterChain:
filter:
name: envoy.filters.network.http_connection_manager
subFilter:
name: envoy.filters.http.router
portNumber: 50051 # application port
patch:
operation: INSERT_BEFORE
value:
name: envoy.filters.http.grpc_json_transcoder
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder
services:
- mycompany.myapi.v1.MyService # your gRPC service
print_options:
add_whitespace: true
always_print_enums_as_ints: false
always_print_primitive_fields: true
preserve_proto_field_names: false
convert_grpc_status: true
proto_descriptor_bin: # base64 encoded proto descriptor 参考: https://www.tetrate.io/blog/grpc-transcoding-with-istio/ 需要设置 proto_descriptor_bin,跟业务逻辑有一定的耦合,如果 proto 文件发生变更,EnvoyFilter 也要跟着更新。 性能方面存疑,没有具体测试过。 |
本 demo 使用 gRPC Gateway,部分代码如下: blog-microservices/cmd/blog/main.go Lines 72 to 87 in 541be82
|
Kong 插件在 Kubernetes 集群的使用如下: apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <grpc-gateway-example>
config:
proto: path/to/hello.proto
plugin: grpc-gateway
---
apiVersion: networking/v1beta1
kind: Ingress
metadata:
name: {ROUTE}
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: <grpc-gateway-example>
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
serviceName: echo
servicePort: 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: