Git Product home page Git Product logo

grpc-go's Introduction

Go Language GRPC Server and Client

This is a basic gRPC server and client written in Go. It is based on the gRPC documentation


Proof of Concept

* Client -- > Server (Regular Architecture)
* This is synchoronus and slow and can't be scaled (in case lots of server and mircoservices)

Concept of gRPC

* Client --> Server (Remote Calls)
* This helps in calling the function directly from client to the server. It's like we have server and the client at the same place
* Here instead of JSON, we use protobuf. Due to having small size the communication is fast


Client ===== Server

  • Streaming
  • Could be scaled to quite extent
  • Continuous flow of data
  • Asynchoronus that means there is no waiting for the server to resond back and hence it's fast
  • Microservices and the BlockChain peers communication


Types of Communication that can happen?

  • 1. Regular Request and Response (Unary API)

  • 2. Server Streaming

    • The client makes a request to the server and then there is a stream of message
  • Client Streaming

    • The client sends a stream of requests to the server and then the server by the response
  • Bi-Directional Streaming

    • Client and Server both communicate using streams. It completely asynchoronus in the nature. There is no order while sending that either client should send first or the server should.

ProtoBuf File for the configuration

Here we have all the streaming configuration done and ready for the communication between the server and client. The direction of the stream and their returns has been declared. We now have to work on code, to generate some code.

Here we also need to create the protobuf file for the communication and the same could be done using

protoc --go_out=. --go-grpc_out=.

If in case the code is not running we need to download some dependencies * go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest * go get -u google.golang.org/protobuf/cmd/protoc-gen-go * go install google.golang.org/protobuf/cmd/protoc-gen-go * go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc * go install google.golang.org/grpc/cmd/protoc-gen-go-grpc


Once we are done with creation of the .pb file, run the tidy command in the kernel to get all the dependencies



Talks on the API

  • In the server as well as the client for the unary we have seperate relation, where the client will send one request and the server will respond with the HelloResponse**

  • We are sending a request with no params but we are expecting some response and the server should respond


  • For the part of server stream, the server is going to send the stream of response to the client and then client is only going to send the request to the server. This all will be handled by the sayHelloServerStreaming

  • Similarly in the case of the client streaming, client will send the stream of the data towards the server and the server will response to the client with one response using this function callsayHelloClientStream

For the bidirectional streaming both the server as well the as the client will keep sending the stream to each other



Running the code

  • Load up all the dependencies use go mod tidy

  • Whichever load function needs to performed uncomment that one

  • Launch server, port defined is :8080

grpc-go's People

Contributors

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