An example of gRPC streaming messages in Go.
First, you need the Go programming language.
In addition, you need the protobuf
, protoc-gen-go
, and protoc-gen-go-grpc
utilities.
You can install these on the Mac via brew
:
brew install go
brew install protobuf
brew install protoc-gen-go
brew install protoc-gen-go-grpc
To compile the program, run make compile
.
Run the server first.
$ ./server
The server will listen for a stream of people. For each received person, it will send an immediate message back and then send another message five seconds later.
To stop the server, press control + C.
Then run the client.
$ ./client
The client will query details about a person from the console. Provide a name, location, and a number with spaces in
between. E.g...
halprin Internet 768
The client will then stream the person to the server five times with 10 seconds in between. In between these 10 seconds, you will receive both messages back from the server between sends.
After sending the person the fifth time, you will be able to type in details for another person like before.
To stop the client, press control + C or press return without providing any person details when the client is querying for a person.