Upgrade to Pro — share decks privately, control downloads, hide ads and more …

5 years on air - Andrii Bereza

GDG Cherkasy
December 16, 2017
34

5 years on air - Andrii Bereza

Grpc Introduction

GDG Cherkasy

December 16, 2017
Tweet

More Decks by GDG Cherkasy

Transcript

  1. ★ ★ ★ ★ { "id": 1, "name": "Solaire of

    Astora", "description": "Praise The gRPC!", "hollow": null }
  2. message User { int32 id = 1; string name =

    2; bool administrator = 3; } message name property type property name property index gRPC
  3. service HelloService { rpc Hello(HelloRequest) returns (HelloResponse); } message HelloRequest

    { string name = 1; } message HelloResponse { string response = 1; } service name service method request type response type gRPC
  4. class HelloService: HelloServiceImplBase() { } override fun hello(request: HelloRequest, responseObserver:

    StreamObserver<HelloResponse>) { } responseObserver.onNext( HelloResponse.newBuilder() .setResponse("Hello, " + request.name) .build() ) responseObserver.onCompleted()
  5. val channel = ManagedChannelBuilder.forAddress("localhost", 4444) .build(); val request = HelloRequest.newBuilder()

    .setName("WALL-E") .build() val response = HelloServiceGrpc.newBlockingStub(channel) .hello(request) HelloServiceGrpc.newStub(channel) .hello(request, object: StreamObserver<HelloResponse> { override fun onNext(value: HelloResponse?) { println("I'm not alone!") } override fun onError(t: Throwable?) {} override fun onCompleted() {} })