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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
タスクの複雑さでモデルを選ぶ ── Thompson Samplingで動かす“トークン/コスト最適化
satohy0323
0
570
AI時代のYAGNI:「爆速で無駄になった機能」からの学び / 20260720 Naoki Takahashi
shift_evolve
PRO
3
380
データエンジニアリングとドメイン駆動設計
masuda220
PRO
4
120
生成AI×AWS CDK×AWS FISで"振り返れる"ミニGameDayをつくろう
yoshimi0227
1
430
AICoEでAIネイティブ組織への進化
yukiogawa
0
200
インフラと開発の垣根を超えていき!〜元AWSインフラエンジニアがAWS開発で奮闘している話〜
hatahata021
3
300
世界、断片、モデル。そして理解
ardbeg1958
1
130
AI x 開発生産性を取り巻く予算戦略と投資対効果
i35_267
1
270
大量データに対しても、生成AIを用いてリーズナブルにデータ加工をしたい!Databricksのai_queryについて調べてみた
kamoshika
1
220
OpenTelemetryにおけるGoのゼロコード・コンパイル時計装について #fukuokago
quiver
0
130
kaonavi Tech Night#1
kaonavi
0
120
AI、CDK と協働する Full TypeScript アプリケーション開発 / Full TypeScript Application with AI and CDK
geekplus_tech
2
410
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Technical Leadership for Architectural Decision Making
baasie
3
440
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
350
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
250
Designing for Performance
lara
611
70k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
A Tale of Four Properties
chriscoyier
163
24k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
420
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
180
How to make the Groovebox
asonas
2
2.3k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
210
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