5 reasons to use gRPC

Photo by Tony Hand on Unsplash

Simple definition

service Service {
rpc DoSomething (InputRequest) returns (OutputResponse);
}

message InputRequest {
string message = 1;
}

message OutputResponse {
string message = 1;
}

Cross-language support

Easy to use

protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/service.proto
public class ServiceImpl extends ServiceGrpc.ServiceImplBase {
...
}
...
public void start() throws IOException {
Server server = ServerBuilder.forPort(8080)
.addService(new ServiceImpl())
.build();

// Start the server
server.start();
...
}
...
ManagedChannel channel = ManagedChannelBuilder.forTarget("localhost:8080")
.usePlaintext(true)
.build();
...
...
ServiceGrpc.ServiceBlockingStub stub = ServiceGrpc.newBlockingStub(channel);
ServiceOuterClass.InputRequest request =
ServiceOuterClass.InputRequest.newBuilder()
.setMessage("Ray")
.build();

ServiceOuterClass.OutputResponse response = stub.doSomething(request);
...

It’s really fast

Photo by Joe Neric on Unsplash

Built-in timeout

response = serviceStub.withDeadlineAfter(deadlineMs, TimeUnit.MILLISECONDS).doSomething(request); 

Conclusion

Photo by Nghia Le on Unsplash

--

--

--

🚀 Marvelous Senior Backend Software Developer 📚 Like to share my knowledge 🎤 Beginner Public Speaker 🏠💻 Live and work in London https://github.com/oleg-sta

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

Recommended from Medium

DogeDao — Project Update

My Internship at OASIS INFOBYTE

Hack Africa: Announcing Stellar

Setting up a Raspberry Pi cluster

Algorand Hackathon Submission Guide

Returning 575 Terabytes of storage space back to our users

Four Major Reasons To Use A Cloud-Based Authoring Tool In 2021 (And What Features To Look For)

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
Oleg Stadnichenko

Oleg Stadnichenko

🚀 Marvelous Senior Backend Software Developer 📚 Like to share my knowledge 🎤 Beginner Public Speaker 🏠💻 Live and work in London https://github.com/oleg-sta

More from Medium

REST Vs GRAPHQL Vs GRPC

What’s New in KivaKit 1.5

Parallel Run Pattern

Domain Modelling 1: A problem you didn’t know you have