Grpc NetWorkFilter 介绍
Grpc NetWorkFilter 介绍
使用 grpc 调用服务提供程序
定义Pixiu配置文件
static_resources:
listeners:
- name: "net/http"
protocol_type: "HTTP"
address:
socket_address:
address: "0.0.0.0"
port: 8881
filter_chains:
filters:
- name: dgp.filter.httpconnectionmanager
config:
route_config:
routes:
- match:
prefix: "/api/v1"
route:
cluster: "test-grpc"
cluster_not_found_response_code: 505
http_filters:
- name: dgp.filter.http.grpcproxy
config:
path: /mnt/d/WorkSpace/GoLandProjects/dubbo-go-pixiu/samples/http/grpc/proto
- name: dgp.filter.http.response
config:
server_name: "test-http-grpc"
generate_request_id: false
config:
idle_timeout: 5s
read_timeout: 5s
write_timeout: 5s
clusters:
- name: "test-grpc"
lb_policy: "RoundRobin"
endpoints:
- socket_address:
address: 127.0.0.1
port: 50001
protocol_type: "GRPC"
timeout_config:
connect_timeout: "5s"
request_timeout: "10s"
shutdown_config:
timeout: "60s"
step_timeout: "10s"
reject_policy: "immediacy"
Grpc 服务器在“集群”中定义
目前 http 请求仅支持 json body 解析参数
准备服务器
generate pb files under with command:
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative hello_grpc.proto
启动 Server
go run server.go
启动 Pixiu
./dubbo-go-pixiu gateway start --config {CURRENT_PATH}/samples/http/grpc/pixiu/conf.yaml
使用 curl 进行测试
使用以下命令运行命令 curl:
curl http://127.0.0.1:8881/api/v1/provider.UserProvider/GetUser
curl http://127.0.0.1:8881/api/v1/provider.UserProvider/GetUser -X POST -d '{"userId":1}'
如果响应正文是 json,则
Content-Type
的标头将设置为application/json
。如果它只是一个纯文本,则Content-Type
的标题是text/plain
。
最后修改 January 4, 2024: docs: network filter grpc (#2890) (bbc4a6f74a)