cd /opt
git clone https://github.com/grpc/grpc-go
cd /opt/grpc-go/examples/helloworld/helloworld/
git clone https://github.com/protocolbuffers/protobuf
protoc --descriptor_set_out=helloworld.pb --include_imports \
--proto_path=$PWD --proto_path=$PWD/protobuf/src helloworld.proto
curl http://127.0.0.1:9180/apisix/admin/protos/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"content" : "'"$(base64 -w0 helloworld.pb)"'"
}'
curl http://127.0.0.1:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri":"/grpctest",
"plugins":{
"grpc-transcode":{
"proto_id":"1",
"service":"helloworld.Greeter",
"method":"SayHello"
}
},
"upstream":{
"scheme":"grpc",
"type":"roundrobin",
"nodes":{
"127.0.0.1:50051":1
}
}
}'
cd /opt/grpc-go/examples/helloworld/helloworld/
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
helloworld.proto
cd /opt/grpc-go/examples/greeter_server/helloworld/
go run server.go
curl -X POST -H 'content-type: application/json' \
-v --raw http://127.0.0.1:9080/grpctest -d '
{
"type":"7",
"serviceurl" :"xxxx",
"reqdata" :{
"fields": {
"foo": {"string_value":"xxx"},
"bar": {"number_value":666}
}
},
"source":"3"
}'
grpc-go server logs:
2023/01/22 19:10:40 server listening at [::]:50051
2023/01/22 19:10:42 Received: reqdata:{fields:{key:"bar" value:{number_value:666}} fields:{key:"foo" value:{string_value:"xxx"}}} type:"7" serviceurl:"xxxx" source:"3"
2023/01/22 19:10:42 {"reqdata":{"bar":666,"foo":"xxx"},"type":"7","serviceurl":"xxxx","source":"3"}