Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
gRPC on Android @DroidconSF Report
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
TakuSemba
November 20, 2017
Technology
640
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
gRPC on Android @DroidconSF Report
TakuSemba
November 20, 2017
More Decks by TakuSemba
See All by TakuSemba
Customize & Debug ExoPlayer @droidkaigi 2020
takusemba
0
2.1k
Jetpack Compose
takusemba
3
3.7k
Protobuf in Kotlin
takusemba
2
2k
Single Activity with MVVM
takusemba
4
1.4k
KotlinConf Report @ca.kt#7
takusemba
2
500
Request in a QUIC way @shibuya.apk#28
takusemba
2
1.1k
Lint for Kotlin @R.kt#3
takusemba
3
1.6k
Auto Release @potatochips#48
takusemba
1
1.3k
Media streaming on Android @droidkaigi 2018
takusemba
6
8.3k
Other Decks in Technology
See All in Technology
知らん間に、回ってる
ming_ayami
0
670
End-to-Endで考える信頼性 —LINEアプリにおけるクライアント開発×SRE連携の実践
maruloop
4
4.4k
AI時代の闇と光
tatsuya1970
0
100
SoccerMaster: A Vision Foundation Model for Soccer Understanding
kzykmyzw
0
110
10年目を迎えた「ABEMA」がどのように AI 活用を推進して、AI 駆動開発にシフトしているのか / How ABEMA, entering its 10th year, is promoting the use of AI and shifting toward AI-driven development
miyukki
0
170
SRE依存からの脱却 運用を開 発チームへ移す、 フルサイ クル開 発体制の実践
joooee0000
0
2.9k
そのドキュメント、自動化しませんか?
yuksew
1
200
AI Driven AI Governance
pict3
0
460
「最後に責任を取るのはチーム」— 人間のPRレビューを最小化してアップデートしたメンタルモデル
jnishime_dresscode
0
800
Claude Code公式skillで 自分の仕事を少しずつ手放そう!(Claude Code開発ノウハウ大公開スペシャル by クラスメソッド)
kaym
1
440
穢れた技術選定について
watany
17
5.1k
見守りエージェントを作ってみた(ローカルLLM + Hermes Agent)
happysamurai294
0
100
Featured
See All Featured
Deep Space Network (abreviated)
tonyrice
0
230
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
GraphQLとの向き合い方2022年版
quramy
50
15k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
420
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
650
It's Worth the Effort
3n
188
29k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
470
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
580
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Site-Speed That Sticks
csswizardry
13
1.3k
The browser strikes back
jonoalderson
0
1.4k
Transcript
gRPC on Android TakuSemba CyberAgent.Inc
@takusemba https://github.com/TakuSemba
Droidcon SF
None
What’s gRPC?
gRPC ɾProtocol Buffers ɾRemote Procedure Call ɾHTTP/2
ɾProtocol Buffers ɾRemote Procedure Call ɾHTTP/2 gRPC
ɾProtocol Buffers ɾRemote Procedure Call ɾHTTP/2 gRPC
What’s Protocol Buffers?
ɾBinary based transmission Protocol Buffers ɾAvailable for many languages ɾFaster
than Json
ɾBinary based transmission ɾAvailable for many languages ɾFaster than Json
Protocol Buffers
ɾBinary based transmission ɾAvailable for many languages ɾFaster than Json
Protocol Buffers
Protocol BuffersͰͷ௨৴jsonͱൺͯૣ͍ͷ͔ IUUQTRJJUBDPNUBLVTFNCBJUFNTGFBCEBEDFEEC
Let’s gRPC
message CoffeeRequest { string name = 1; } Request //coffee.proto
message CoffeeResponse { int32 price = 1; string name =
2; string message = 3; } Response //coffee.proto
service Coffee { rpc Order (CoffeeRequest) returns (CoffeeResponse) {} }
Service //coffee.proto
Service service Coffee { rpc Order (CoffeeRequest) returns (CoffeeResponse) {}
} service Coffee { rpc Order (stream CoffeeRequest) returns (CoffeeResponse) {} } service Coffee { rpc Order (CoffeeRequest) returns (stream CoffeeResponse) {} } service Coffee { rpc Order (stream CoffeeRequest) returns (stream CoffeeResponse) {} }
syntax = "proto3"; option java_package = "com.takusemba.grpc.android.protos"; option go_package =
"protos"; package Coffee; message CoffeeRequest { string name = 1; } message CoffeeResult { string message = 1; } service Coffee { rpc Order (CoffeeRequest) returns (CoffeeResult) {} } //coffee.proto
->% curl -OL https://github.com/google/protobuf/releases/download/v3.5.0/ protobuf-java-3.5.0.tar.gz ->% tar -zxvf protobuf-java-3.5.0.tar.gz ->%
cd protobuf-3.5.0 ->% ./configure ->% make ->% sudo make install ->% protoc —version // -> libprotoc 3.5.0 :) //protoc
->% git clone
[email protected]
:grpc/grpc-java.git ->% cd grpc-java ->% git checkout
-b v1.7.0 ->% cd compiler ->% make ->% ../gradlew java_pluginExecutable ->% cp build/exe/java_plugin/protoc-gen-grpc-java /usr/local/bin //protoc-gen-grpc-java
->% protoc coffee.proto --grpc-java_out=lite:. --java_out=. --plugin=protoc-gen- grpc-java=/usr/local/bin/protoc-gen-grpc-java //generate proto files
for client ->% protoc --go_out=plugins=grpc:. coffee.proto //generate proto files for server Generate Proto Files
Generate Proto Files
gRPC on Android classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.2' implementation "io.grpc:grpc-okhttp:1.7.0" implementation "io.grpc:grpc-protobuf:1.7.0" implementation
"io.grpc:grpc-stub:1.7.0" implementation "javax.annotation:javax.annotation-api:1.2" //build.gradle //app/build.gradle
gRPC on Android val channel = ManagedChannelBuilder.forAddress("10.0.2.2", 8080) .usePlaintext(true) .build()
val stub = CoffeeGrpc.newBlockingStub(channel) val request = CoffeeOuterClass.CoffeeRequest.newBuilder() .setName(“hot coffee") .build() Single .create<CoffeeOuterClass.CoffeeResponse> { it.onSuccess(stub.order(request)) }.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( { /** do something */ }, { /** error handling */ } )
gRPC on Android val channel = ManagedChannelBuilder.forAddress("10.0.2.2", 8080) .usePlaintext(true) .build()
val stub = CoffeeGrpc.newBlockingStub(channel) val request = CoffeeOuterClass.CoffeeRequest.newBuilder() .setName(“hot coffee") .build() Single .create<CoffeeOuterClass.CoffeeResponse> { it.onSuccess(stub.order(request)) }.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( { /** do something */ }, { /** error handling */ } )
gRPC on Android val channel = ManagedChannelBuilder.forAddress("10.0.2.2", 8080) .usePlaintext(true) .build()
val stub = CoffeeGrpc.newBlockingStub(channel) val request = CoffeeOuterClass.CoffeeRequest.newBuilder() .setName(“hot coffee") .build() Single .create<CoffeeOuterClass.CoffeeResponse> { it.onSuccess(stub.order(request)) }.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( { /** do something */ }, { /** error handling */ } )
gRPC on Android val channel = ManagedChannelBuilder.forAddress("10.0.2.2", 8080) .usePlaintext(true) .build()
val stub = CoffeeGrpc.newBlockingStub(channel) val request = CoffeeOuterClass.CoffeeRequest.newBuilder() .setName(“hot coffee") .build() Single .create<CoffeeOuterClass.CoffeeResponse> { it.onSuccess(stub.order(request)) }.subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( { /** do something */ }, { /** error handling */ } )
Demo
gRPC on Android https://github.com/takusemba https://twitter.com/takusemba