Proof of concept for a simple gRPC setup with servers and clients written in multiple languages
Go >= 1.6 has to be installed in your machine
go env GOPATH
and go env GOBIN
must point to directories in your filesystem. go env GOBIN
must be part of your $PATH
.
Easiest way to get this working is to set the following environment variables in your shell init scripts (.basrc
, .zshrc
, ...)
export GOPATH=$HOME
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
mkdir -p $GOPATH/src/github.com/rodrigodiez
cd $GOPATH/src/github.com/rodrigodiez
git clone [email protected]:rodrigodiez/grpc-spike.git
Provides dependency management for the project
go get -u github.com/golang/dep/cmd/dep
Provides go grpc package
go get -u google.golang.org/grpc
Providers go code generator for grpc services and clients
go get -u github.com/golang/protobuf/protoc-gen-go
Provides go code generator for grpc gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
Provides swagger files generator for grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
php >= 5.6 has to be installed in your machine
Provides configuration tools for make (necessary to compile php plugin)
brew install automake autoconf
Provides protocol Buffers compiler (protoc) and php code generator source code
mkdir -p $GOPATH/src/github.com/grpc/
cd $GOPATH/src/github.com/grpc/
git clone [email protected]:grpc/grpc.git
docker and docker-compose have to be installed in your machine
cd $GOPATH/src/github.com/rodrigodiez/grpc-spike
make all
May take a while
- Compiles php code generator plugin
- Generates Go and php code from
.proto
files - Compiles Go
server
,client
andgw
applications - Build docker images to run php and nodejs code
Inspect the Makefile
for more fine grained tasks
Run one or the other...
# starts a GO server and a JSON gateway
docker-compose up
# starts a NODE server and a JSON gateway
docker-compose -f docker-compose-node.yml up
In a different terminal, experiment with the following operations...
# go
bin/client --command=add --recording "<name of the recording>"
# php
docker run -ti --rm --network grpcspike_default kobaltmusic/grpc-spike:php php bin/add.php "<name of the recording>"
# node
docker run -ti --rm --network grpcspike_default kobaltmusic/grpc-spike:node node add.js "name of the recording"
# gateway
curl -X POST http://localhost:8080/v1/recordings -d '{"recording": {"name": "name of the recording", "author": { "name": "HTTP/JSON"}}}'
# go
bin/client --command=list
# php
docker run -ti --rm --network grpcspike_default kobaltmusic/grpc-spike:php php bin/list.php
# node
docker run -ti --rm --network grpcspike_default kobaltmusic/grpc-spike:node node list.js
# gateway
curl http://localhost:8080/v1/recordings
# go
bin/client --command=stream
# php
docker run -ti --rm --network grpcspike_default kobaltmusic/grpc-spike:php php bin/stream.php
# node
docker run -ti --rm --network grpcspike_default kobaltmusic/grpc-spike:node node stream.js