Git Product home page Git Product logo

grpc-streaming-demo's Introduction

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 streaming

By 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.

# 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.proto

The 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:

go run server.go

You can run the client using:

python3 client.py

image

grpc-streaming-demo's People

Contributors

ridha avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.