gRPC — Message Types

Most important thing is to have in mind is all of the rules in Protocol Buffers applies here. Whatever you can do in protocol buffers you could do it with gRPC.

If you have no experience with Protocol buffers, have a look at this

service Student {
rpc GetByStudentNumber (Request) returns (Response)
}

Above is the way to define a simple service in gRPC. I will explain one by one.

  1. service — Keyword to define a gRPC service
  2. Student — Service name
  3. rpc — defines RPC calls ( what the client ask the server )
  4. GetByStudentNumber — Method name
  5. Request — Has to be a message type (no void or primitive data types)
  6. Response — Has to be a message type (no void or primitive data types)

This is what happens once you finish writing the services. The file contains the service for example in the above example I started the service Student. So will call that file as “StudentService”. This service will be inside a protocol buffer message definition.

Yeah !! That’s the name we call it. The Protocol Buffer Message Definition.

When we call the Protocol Buffer compiler it gonna generate the “Client Stub”

Client Stub - Generated source code to the client in order to communicate with the server

and the “Server Interface”.

Server Interface - This has two parts, service we can implement, and another part to handle the serialization and de-serialization during the communication.

Don’t worry gRPC will handle all the serialization part for the communication.

Let’s see an example.

Above example has all four types of messages in gRPC. Unary, Client streaming, Server Streaming, Bidirectional streaming.

First we must install protocol buffer compiler to work with.

here is my article about installing. Check this out.

Once we have the protocol buffer compiler ready to work we can start defining the service definition.

Cheers !!!

--

--

--

Developer ❤️ JS

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Design your landing pages automatically in just a few seconds using artificial intelligence

Docker Image Security for DevSecOps

Ethermon Locations for Rewards & MARKS

Optimization at +-30K RPS

An analysis of Caduceus decentralized edge rendering technology — a breakdown of its native tools…

OSCP 2020 Review — Passed in the #1 attemp being a newbie

GoldFind x IM community AMA RECAP

One small step for career, one giant step for introspection.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ADMAT Bandara

ADMAT Bandara

Developer ❤️ JS

More from Medium

Connecting to secured gRPC server using grpcurl

Distributed transactions spanning multiple databases with Scalar DB (Part 1)

Provision a Object Storage cluster with Leaseweb Dedicated Server API

Idempotent Consumer