1 Star 0 Fork 166

东郡 / Apache APISIX incubating

forked from iresty / Apache APISIX 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
grpc-transcoding.md 2.76 KB
一键复制 编辑 原始数据 按行查看 历史

Chinese

Name

HTTP(s) -> APISIX -> gRPC server

Proto

Attributes

  • content: .proto file's content.

Add a proto

Here's an example, adding a proto which id is 1:

curl http://127.0.0.1:9080/apisix/admin/proto/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "content" : "syntax = \"proto3\";
    package helloworld;
    service Greeter {
        rpc SayHello (HelloRequest) returns (HelloReply) {}
    }
    message HelloRequest {
        string name = 1;
    }
    message HelloReply {
        string message = 1;
    }"
}'

Attribute List

Name Requirement Description
proto_id required .proto content id.
service required the grpc service name.
method required the method name of grpc service.

How To Enable

Here's an example, to enable the grpc-transcode plugin to specified route:

  • attention: the route's option service_protocol must be grpc
  • the grpc server example:grpc_server_example
curl http://127.0.0.1:9080/apisix/admin/routes/111 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "methods": ["GET"],
    "uri": "/grpctest",
    "service_protocol": "grpc",
    "plugins": {
        "grpc-transcode": {
            "proto_id": "1",
            "service": "helloworld.Greeter",
            "method": "SayHello"
        }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:50051": 1
        }
    }
}'

Test Plugin

The above configuration proxy :

curl -i http://127.0.0.1:9080/grpctest?name=world

response:

HTTP/1.1 200 OK
Date: Fri, 16 Aug 2019 11:55:36 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server
Proxy-Connection: keep-alive

{"message":"Hello world"}

This means that the proxying is working.

Lua
1
https://gitee.com/ldongjun/apisix.git
git@gitee.com:ldongjun/apisix.git
ldongjun
apisix
Apache APISIX incubating
master

搜索帮助