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

gRPC for Android

gRPC for Android

introduction to gRPC for Android

Daichi Furiya (Wasabeef)

August 08, 2015
Tweet

More Decks by Daichi Furiya (Wasabeef)

Other Decks in Programming

Transcript

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

    Objective-c • Node.js • PHP • Python • Ruby
  2. VTFSQSPUP syntax = "proto3"; package user; message Profile { string

    id = 1; string name = 2; int64 createdAt = 3; }
  3. *OTUBMM # git clone [email protected]:google/protobuf.git # cd protobuf # git

    checkout v3.0.0-alpha-3.1 # ./autogen.sh # ./configure # make # make check # sudo make install
  4. 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) {} }
  5. 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);
 });