gRPC for Android

gRPC for Android

introduction to gRPC for Android

6dd0483f1353a4a359e92633cfd65c64?s=128

Daichi Furiya (Wasabeef)

August 08, 2015
Tweet

Transcript

  1. H31$GPS"OESPJE !XBTBCFFG@KQ

  2. "CPVU.F @wasabeef_jp CyberAgent, Inc.

  3. 8IBUJTH31$

  4. )551

  5. )551 • Binary • Multiplexed • Server Push • Header

    compression
  6. -BOHVBHFT 

  7. -BOHVBHFT • C/C++ • C# • Java • Go •

    Objective-c • Node.js • PHP • Python • Ruby
  8. 8IBUJT 1SPUPDPM#VFST

  9. 1SPUPDPM#VFST • IDL • Binary • Support code generation (protoc)

  10. VTFSKTPO { id: 1, name: “wasabeef”, createdAt: “20150808” }

  11. VTFSQSPUP syntax = "proto3"; package user; message Profile { string

    id = 1; string name = 2; int64 createdAt = 3; }
  12. QSPUPCVG

  13. *OTUBMM # git clone git@github.com:google/protobuf.git # cd protobuf # git

    checkout v3.0.0-alpha-3.1 # ./autogen.sh # ./configure # make # make check # sudo make install
  14. *OTUBMM # protoc --version libprotoc 3.0.0

  15. 3FUSPU

  16. $POWFSUFS

  17. $POWFSUFST • GSON • Jackson • Moshi • Protobuf •

    Simplexml • Wire
  18. 1SPUP$POWFSUFS Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.example.com") .converter(new ProtoConverter()) .build();

  19. 0UIFST • Wire (Square) • FlatBuffers (Google) • Message Pack

    (Sadayuki Furuhashi)
  20. 6TFH31$

  21. FDIPQSPUP syntax = "proto3"; option java_package = “jp.wasabeef.proto.echo”; option go_package

    = "echo"; package echo; message EchoRequest { string message = 1; } message EchoReply { string message = 1; } service Echo { rpc Echo (EchoRequest) returns (EchoReply) {} }
  22. $PEFHFOFSBUJPO • protobuf-gradle-plugin • (protoc) • (protoc-gen-grpc-java)

  23. HSQDKBWB

  24. %FQFOEFODJFT compile 'io.grpc:grpc-all:x.y.z'

  25. TBNQMF AsyncSubject<String> subject = AsyncSubject.create(); new Thread(() -> { Channel

    channel = OkHttpChannelBuilder.forAddress(“grpc.wasabeef.jp”, 8443)
 .setConnectionSpec(ConnectionSpec.MODERN_TLS)
 .sslSocketFactory((SSLSocketFactory)SSLSocketFactory.getDefault())
 .build();
 
 EchoGrpc.EchoBlockingStub stub = EchoGrpc.newBlockingStub(channel); 
 Echo.EchoRequest req = new Echo.EchoRequest();
 req.setMessage(“YES YES YES!"); 
 Echo.EchoReply reply = stub.echo(req);
 subject.onNext(reply.getMessage());
 subject.onCompleted();
 }).start();
 
 subject.observeOn(AndroidSchedulers.mainThread()).subscribe(msg -> {
 Log.d(“ECHO LOG” ,msg);
 });
  26. HSQDDPNNPO

  27. %PDVNFOUT https://github.com/grpc/grpc-common

  28. UIBOLT