Skip to content
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

feat grpc proxy doc && test case #691

Merged
merged 14 commits into from
Nov 1, 2019
39 changes: 36 additions & 3 deletions .travis/linux_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export_or_prefix() {
}

create_lua_deps() {
WITHOUT_DASHBOARD=1 sudo luarocks make --lua-dir=${OPENRESTY_PREFIX}/luajit rockspec/apisix-dev-1.0-0.rockspec --tree=deps --only-deps --local
sudo luarocks make --lua-dir=${OPENRESTY_PREFIX}/luajit rockspec/apisix-dev-1.0-0.rockspec --tree=deps --only-deps --local
sudo luarocks install --lua-dir=${OPENRESTY_PREFIX}/luajit lua-resty-libr3 --tree=deps --local
echo "Create lua deps cache"
sudo rm -rf build-cache/deps
Expand Down Expand Up @@ -66,15 +66,28 @@ do_install() {
ls -l ./
if [ ! -f "build-cache/grpc_server_example" ]; then
sudo apt-get install golang

git clone https://github.com/iresty/grpc_server_example.git grpc_server_example

cd grpc_server_example/
go build -o grpc_server_example main.go
mv grpc_server_example ../build-cache/
cd ..
fi

if [ ! -f "build-cache/proto/helloworld.proto" ]; then
git clone https://github.com/iresty/grpc_server_example.git grpc_server_example
cd grpc_server_example/
mv proto/ ../build-cache/
cd ..
fi

if [ ! -f "build-cache/grpcurl" ]; then
sudo apt-get install golang
git clone https://github.com/fullstorydev/grpcurl.git grpcurl
cd grpcurl
go build -o grpcurl ./cmd/grpcurl
mv grpcurl ../build-cache/
cd ..
fi
}

script() {
Expand All @@ -91,10 +104,30 @@ script() {
./bin/apisix start
mkdir -p logs
sleep 1

#test grpc proxy
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"methods": ["POST", "GET"],
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
"uri": "/helloworld.Greeter/SayHello",
"service_protocol": "grpc",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:50051": 1
}
}
}'

./build-cache/grpcurl -insecure -import-path ./build-cache/proto -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello

nic-chen marked this conversation as resolved.
Show resolved Hide resolved
sleep 1

./bin/apisix stop
sleep 1
make check || exit 1
APISIX_ENABLE_LUACOV=1 prove -Itest-nginx/lib -r t

}

after_success() {
Expand Down
21 changes: 21 additions & 0 deletions .travis/osx_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ do_install() {
cd grpc_server_example/
go build -o grpc_server_example main.go
cd ..

brew install grpcurl
}

script() {
Expand All @@ -64,6 +66,25 @@ script() {
sudo make run
mkdir -p logs
sleep 1

#test grpc proxy
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"methods": ["POST", "GET"],
"uri": "/helloworld.Greeter/SayHello",
"service_protocol": "grpc",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:50051": 1
}
}
}'
nic-chen marked this conversation as resolved.
Show resolved Hide resolved

grpcurl -insecure -import-path ./grpc_server_example/proto -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello

sleep 1

sudo make stop

sleep 1
Expand Down
52 changes: 52 additions & 0 deletions doc/grpc-proxy-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[English](grpc-proxy.md)
# grpc-proxy

通过apisix代理grpc连接,并使用apisix的大部分特性管理你的grpc服务。
nic-chen marked this conversation as resolved.
Show resolved Hide resolved



### 参数

* `service_protocol": "`: 这个 route 的属性`service_protocal` 必须设置为 `grpc`
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
* `uri`: 格式为 /service/method 如:/helloworld.Greeter/SayHello



### 示例

#### 创建代理grpc的route

在指定 route 中,代理 grpc 服务接口:

* 注意: 这个 route 的属性`service_protocal` 必须设置为 `grpc`
* 例子所代理的 grpc 服务可参考:[grpc_server_example](https://github.com/nic-chen/grpc_server_example)

```shell
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"methods": ["POST", "GET"],
nic-chen marked this conversation as resolved.
Show resolved Hide resolved
"uri": "/helloworld.Greeter/SayHello",
"service_protocol": "grpc",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:50051": 1
}
}
}'
```


#### 测试

访问上面配置的 route:

```shell
$ grpcurl -insecure -import-path /pathtoprotos -proto helloworld.proto -d '{"name":"apisix"}' 127.0.0.1:9443 helloworld.Greeter.SayHello
{
"message": "Hello apisix"
}
```

这表示已成功代理。