gRPC

Nedir?

Client uygulamaların,server uygulamadaki bir fonksiyonu sanki Client içinde tanımlıymış gibi uzaktan çağırmasına denir. HTTP/2 Protokolünde çalışan bir RPC (Remote Procedure Call) Framework’ü denilebilir. Protobuf formatından dolayı iletişim çok daha hızlıdır. HTTP/2 protokolü üzerinden çalıştığından dolayı minimum TCP bağlantısına ihtiyaç duyar. (HTTP/1 head-of-line-blocking problem)

HTTP/2 Multiplexing

Birden fazla analog veya dijital sinyalin birleştirilip tek bir sinyal haline getirilmesidir. (Telefon görüşmelerinin tek fiziki kablo üzerinden geçmesi)

Protobuf (.proto)

Dil ve platformdan bağımsız Google tarafından geliştirilmiş bir dildir. Proto dosyaları uzaktan çalıştırılması gereken kodlar için alt yordam desteği sunar. Dilden bağımsız olduğundan dolayı desteklediği diller üzerinden objelere dönüştürülür. Bu da serialize/deserialize işlemlerinin çok hızlı gerçekleştirilmesini sağlar.

Örnek bir .proto dosyası:

Protobuf  - Desteklenen Tipler

(NOT: Tüm tipler default olarak nullabledır)

double, float, int32, int64, uint32, uint64, sint32, sint64, fixed32, fixed64, sfixed32, sfixed64, bool, string, bytes

Protobuf  - Desteklenen Advanced Tipler

Enumurations:

message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 result_per_page = 3;
  enum Corpus {
    UNIVERSAL = 0;
    WEB = 1;
    IMAGES = 2;
    LOCAL = 3;
    NEWS = 4;
    PRODUCTS = 5;
    VIDEO = 6;
  }
  Corpus corpus = 4;
}

Diğer Message alanlarının kullanılması:

message SearchResponse {
  repeated Result results = 1;
}

message Result {
  string url = 1;
  string title = 2;
  repeated string snippets = 3;
}

Nested:

message SearchResponse {
  message Result {
    string url = 1;
    string title = 2;
    repeated string snippets = 3;
  }
  repeated Result results = 1;
}

Unknown Fields:

import "google/protobuf/any.proto";

message ErrorStatus {
  string message = 1;
  repeated google.protobuf.Any details = 2;
}

OneOf:

message SampleMessage {
  oneof test_oneof {
    string name = 4;
    SubMessage sub_message = 9;
  }
}

Map:

map<string, Project> projects = 3;

Proto Generate Class

protoc --proto_path=IMPORT_PATH --csharp_out=DST_DIR

CLI: http://google.github.io/proto-lens/installing-protoc.html

Dezavantajları

Okunabilir bir çıktısı bulunmamaktadır.

Çok detaylı bir dökümantasyonu bulunmamaktadır.

Oldukça küçük bir community’si bulunmaktadır. StackOverflow’da açılan soru sayısı oldukça düşük.

Benchmark

Compressing karşlaştırması:

Microsoft MSDN’in gRPC dökümantasyonu:

Java-to-java:

Serialize / Deserialize:

REST / gRPC:



Yönlendirmeler

https://itnext.io/using-grpc-with-tls-golang-and-react-no-envoy-92e898bf8463

http://google.github.io/proto-lens/installing-protoc.html

https://developers.google.com/protocol-buffers/docs/proto3

https://github.com/grpc

https://github.com/grpc/grpc-web