Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ridha/grpc-streaming-demo
A quick demo of bi-directional streaming RPC's using grpc, go and python3
https://github.com/ridha/grpc-streaming-demo
grpc
Last synced: 3 months ago
JSON representation
A quick demo of bi-directional streaming RPC's using grpc, go and python3
- Host: GitHub
- URL: https://github.com/ridha/grpc-streaming-demo
- Owner: ridha
- Created: 2017-03-09T06:05:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-03-11T16:08:41.000Z (over 7 years ago)
- Last Synced: 2024-06-20T11:50:20.433Z (5 months ago)
- Topics: grpc
- Language: Go
- Homepage:
- Size: 197 KB
- Stars: 166
- Watchers: 9
- Forks: 39
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
- awesome-grpc - Streaming RPC's using gRPC - A quick demo of bi-directional streaming RPC's using grpc, Go and Python (Resources / Examples)
README
Streaming RPC's using gRPC
--------------------------gRPC is a language-neutral, platform-neutral RPC framework that is quickly taking on JSON/HTTP
as the recommended way to communicate between microservices.Its main selling points are:
- Communication is based on HTTP2 transport. This provides all the advantages of the HTTP2 (compression, multiplexing, streaming)
- Well-defined schemas via Protocol Buffers 3
- Automatic client code generation for 10 different languages.
- Bi-directional streamingBy default, gRPC uses Protocol Buffers as the Interface Definition Language (IDL) and as its underlying message interchange format.
In this project, we'll implement a simple PrimeFactorService that returns a stream of the prime factors of the numbers passed to it
in a request.
I decided to make my gRPC server in Go and client in Python.
The client program will read from stdin and will immediately push it to the service.Generate gRPC code for server and client
----------------------------------------We are going to use gRPC to generate libraries for Go and Python 3.
To generate the Go code, you'll need to install protoc_... _protoc: https://github.com/google/protobuf/#protocol-compiler-installation
.. code-block:: bash
# Python client
$ pip3 install -U grpcio grpcio-tools
$ python3 -m grpc_tools.protoc -I protobuf/ --python_out=. --grpc_python_out=. protobuf/primefactor.proto
# Go
$ protoc -I protobuf/ --go_out=plugins=grpc:protobuf/ protobuf/primefactor.protoThe first command will generate primefactor_pb2.py and primefactor_pb2_grpc.py.
The latter will generate primefactor.pb.go.To start the server, simply run:
.. code-block:: bash
go run server.go
You can run the client using:
.. code-block:: bash
python3 client.py
.. image:: demo.gif