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
Search
Moyuru Aizawa
September 15, 2017
Programming
1.1k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
gRPC
Moyuru Aizawa
September 15, 2017
More Decks by Moyuru Aizawa
See All by Moyuru Aizawa
BLUETOOTH_SCAN and iBeacon
lvla
1
150
graphicsLayer
lvla
0
290
BluetoothDevice.getName()に裏切られた話
lvla
0
410
Jetpack Composeで画像クロップ機能を実装する
lvla
0
1.3k
Jetpack Compose drag gesture and pinch gesture
lvla
1
4.3k
Jetpack Compose Layout API
lvla
1
710
BLEを使ったアプリを継続的に開発するために
lvla
0
1.1k
RecyclerView.ItemAnimator
lvla
1
380
RecycledViewPool
lvla
1
290
Other Decks in Programming
See All in Programming
エージェンティックRAGにAWSで入門しよう!
har1101
9
1.7k
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
220
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
Webフレームワークの ベンチマークについて
yusukebe
0
180
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
280
Performance Engineering for Everyone
elenatanasoiu
0
210
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
The NotImplementedError Problem in Ruby
koic
1
920
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
160
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.5k
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
190
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
920
Featured
See All Featured
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
330
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Test your architecture with Archunit
thirion
1
2.3k
Mind Mapping
helmedeiros
PRO
1
260
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Transcript
gRPC @MoyuruAizawa
Ѫᖒ๖ (Moyuru Aizawa) MoyuruAizawa Contract Developer Pairs Div. Eureka, Inc.
FRESH! Div. CyberAgent, Inc.
None
‣ Live Streaming ‣ Upcoming ‣ Live ‣ Pause ‣
… FRESH!
FRESH!
Polling
Polling Client Server Live Pause
Polling Client Server Live Pause
Polling Client Server Live Pause
Polling Client Server Live Pause
Polling Client Server Live Pause
Polling Client Server Live Pause
Polling Client Server Live Pause
Polling Client Server Live Pause
Polling Client Server Live Pause ແବ!
Polling Client Server Live Pause ͍!!
gRPC
‣ Google ‣ Remote Procedure Call ‣ HTTP/2 ‣ ѹॖϔομʔ
‣ αʔόʔϓογϡ ‣ Protocol Buffers ‣ ετϦʔϜ ‣ … gRPC
gRPC
gRPC Channel(OkHttp2) Binary data
gRPC Serialize/Deserialize … FooServiceStub
Plasma
‣ FRESH!։ൃ ‣ gRPC Stream, Server Sent EventΛ༻͍ͨ൚༻తͳServer Pushϛυϧ ΣΞ
‣ ΫϥΠΞϯτPlasmaʹରͯ͠subscribe͍ͨ͠EventΛૹΔ ‣ Πϕϯτൃੜ࣌ʹPlasma͕ΫϥΠΞϯτʹରͯ͠ใΛૹΔ ‣ https://blog.stormcat.io/post/entry/openfresh-plasma/ Plasma
gRPC Client Plasma
gRPC Client Plasma Connect to server
gRPC Client Plasma Connect to server subscribe Event1
gRPC Client Plasma Connect to server subscribe Event1 Event1
gRPC Client Plasma Connect to server subscribe Event1 Event1
gRPC Client Plasma Connect to server subscribe Event1 Event1 subscribe
Event2
gRPC Client Plasma Connect to server subscribe Event1 Event1 subscribe
Event2 Event2
gRPC Client Plasma Connect to server subscribe Event1 Event1 subscribe
Event2 Event2
gRPC Client Plasma Connect to server subscribe Event1 Event1 subscribe
Event2 Event1 Event2
gRPC Client Plasma Connect to server subscribe Event1 Event1 subscribe
Event2 Event1 Event2
gRPC Client Plasma Connect to server subscribe Event1 Event1 subscribe
Event2 Event1 Event2 ແବͳϦΫΤετͷݮ ϦΞϧλΠϜ
TIPS
‣ Protobuf ‣ ProtoϑΝΠϧͷσʔλఆٛΛݩʹSerialize/Deserializeίʔυͷੜ ɺσʔλΫϥεͷੜ ‣ ProtoϑΝΠϧͷαʔϏεఆٛΛݩʹStubΫϥεͷੜ ‣ Channel ‣
αʔόʔͱͷίωΫγϣϯ ‣ Stub ‣ αʔϏε gRPC
Kotlin and Protobuf
Kotlin and Protobuf
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'com.google.protobuf' apply
plugin: 'com.android.application' apply plugin: 'com.google.protobuf' apply plugin: 'kotlin-android' Kotlin and Protobuf
Channel and Lifecycle
ManagedChannel and Lifecycle onCreate
ManagedChannel and Lifecycle onCreate new ManagedChannel()
ManagedChannel and Lifecycle onCreate new ManagedChannel() FooServiceStubGrpc.newStub(channel)
ManagedChannel and Lifecycle onCreate new ManagedChannel() FooServiceStubGrpc.newStub(channel) stub.bar()
ManagedChannel and Lifecycle onCreate onDestroy channel.shutdownNow() new ManagedChannel() FooServiceStubGrpc.newStub(channel) stub.bar()
ManagedChannel and Lifecycle onCreate onDestroy channel.shutdownNow() the system will simply
kill the activity's hosting process without calling onDestroy new ManagedChannel() FooServiceStubGrpc.newStub(channel) stub.bar()
ManagedChannel and Lifecycle onCreate onDestroy channel.shutdownNow() new ManagedChannel() FooServiceStubGrpc.newStub(channel) stub.bar()
αʔόʔʹແବͳίωΫγϣϯ͕ཷ·͍ͬͯ͘ ΞϓϦ͕όοΫάϥϯυͰ௨৴ͯ͠͠·͏
ManagedChannel and Lifecycle onCreate onDestroy channel.shutdownNow() new ManagedChannel() FooServiceStubGrpc.newStub(channel) stub.bar()
onStart onStop
‣ onStart-onStopͰίωΫγϣϯΛுΔ ‣ ίωΫγϣϯ͕ΕͨStub͑ͳ͘ͳΔͷͰɺStubຖੜ͠ ͢ ‣ FRESH!ͰgRPCͰ௨৴͢Δ༻ͷΫϥεΛ࡞ɻαʔόʔͱͷଓ ͱɺϦΫΤετΛ·ͱΊͨɻ ManagedChannel and
Lifecycle
Reconnection
‣ Channel: αʔόʔͱͷίωΫγϣϯ ‣ ManagedChannel:αʔόʔ͕μϯ͢Δɺ͕ΦϑϥΠϯʹͳΔͳ ͲʹΑͬͯίωΫγϣϯ͕Εͯɺ࠶ଓΛߦͬͯ͘ΕΔɻ Reconnection
Reconnection ͍͔ͭΒManagedChannel͕ૉૣ͘ ࠶ଓͯ͘͠ΕΔͱࡨ͍֮ͯͨ͠?
‣ ͔ͨ͠ʹɺ࠶ଓͯ͘͠ΕΔɻ ‣ ͔͠͠ɺͨΒ͕͔͔࣌ؒΔɻ(5ඵͱ͔10ඵͱ͔) ‣ ࠶ଓ·ͰผͷHTTP/1.1ͷAPIΛୟ͘ Plasma͕RxͰ͍͏PublishSubjectͷΑ͏ͳϛυϧΣΞͳͷͰɺଓ͕Ε͍ͯΔؒʹى͖ͨΠϕϯτΛ औΕͳ͍ͨΊ Reconnection
‣ ͔ͨ͠ʹɺ࠶ଓͯ͘͠ΕΔɻ ‣ ͔͠͠ɺͨΒ͕͔͔࣌ؒΔɻ(5ඵͱ͔10ඵͱ͔) ‣ ࠶ଓ·ͰผͷHTTP/1.1ͷAPIΛୟ͘ Plasma͕RxͰ͍͏PublishSubjectͷΑ͏ͳϛυϧΣΞͳͷͰɺଓ͕Ε͍ͯΔؒʹى͖ͨΠϕϯτΛ औΕͳ͍ͨΊ ‣ ଓঢ়ଶͷมߋΛࢹ͍ͨ͠ͳ͊….
Reconnection
‣ ͔ͨ͠ʹɺ࠶ଓͯ͘͠ΕΔɻ ‣ ͔͠͠ɺͨΒ͕͔͔࣌ؒΔɻ(5ඵͱ͔10ඵͱ͔) ‣ ࠶ଓ·ͰผͷHTTP/1.1ͷAPIΛୟ͘ Plasma͕RxͰ͍͏PublishSubjectͷΑ͏ͳϛυϧΣΞͳͷͰɺଓ͕Ε͍ͯΔؒʹى͖ͨΠϕϯτΛ औΕͳ͍ͨΊ ‣ ଓঢ়ଶͷมߋΛࢹ͍ͨ͠ͳ͊….
Reconnection
TLS 1.2
OkHttpChannelBuilder .forAddress(address, port) .sslSocketFactory(sslSocketFactory) .connectionSpec( ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) .tlsVersions(TlsVersion.TLS_1_2) .build() ) .negotiationType(NegotiationType.TLS)
.build() Build ManagedChannel
OkHttpChannelBuilder .forAddress(address, port) .sslSocketFactory(sslSocketFactory) .connectionSpec( ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) .tlsVersions(TlsVersion.TLS_1_2) .build() ) .negotiationType(NegotiationType.TLS)
.build() Build ManagedChannel
OkHttpChannelBuilder .forAddress(address, port) .sslSocketFactory(sslSocketFactory) .connectionSpec( ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) .tlsVersions(TlsVersion.TLS_1_2) .build() ) .negotiationType(NegotiationType.TLS)
.build() Build ManagedChannel Android 4.1-4.4Ͱ TLS 1.2͕ར༻Ͱ͖ͳ͍
class TlsSocketFactory(private val delegate: SSLSocketFactory) : SSLSocketFactory() { override fun
getDefaultCipherSuites(): Array<String> = delegate.defaultCipherSuites override fun createSocket(s: Socket?, host: String?, port: Int, autoClose: Boolean): Socket = delegate.createSocket(s, host, port, autoClose).let(this::patch) override fun createSocket(host: String?, port: Int): Socket = delegate.createSocket(host, port).let(this::patch) override fun createSocket(host: String?, port: Int, localHost: InetAddress?, localPort: Int): Socket = delegate.createSocket(host, port, localHost, localPort).let(this::patch) override fun createSocket(host: InetAddress?, port: Int): Socket = delegate.createSocket(host, port).let(this::patch) override fun createSocket(address: InetAddress?, port: Int, localAddress: InetAddress?, localPort: Int): Socket = delegate.createSocket(address, port, localAddress, localPort).let(this::patch) override fun getSupportedCipherSuites(): Array<String> = delegate.supportedCipherSuites private fun patch(s: Socket): Socket = s.apply { if (this is SSLSocket) enabledProtocols = arrayOf("TLSv1.2") } } Enable TLS 1.2 https://github.com/square/okhttp/issues/2372
class TlsSocketFactory(private val delegate: SSLSocketFactory) : SSLSocketFactory() { override fun
getDefaultCipherSuites(): Array<String> = delegate.defaultCipherSuites override fun createSocket(s: Socket?, host: String?, port: Int, autoClose: Boolean): Socket = delegate.createSocket(s, host, port, autoClose).let(this::patch) override fun createSocket(host: String?, port: Int): Socket = delegate.createSocket(host, port).let(this::patch) override fun createSocket(host: String?, port: Int, localHost: InetAddress?, localPort: Int): Socket = delegate.createSocket(host, port, localHost, localPort).let(this::patch) override fun createSocket(host: InetAddress?, port: Int): Socket = delegate.createSocket(host, port).let(this::patch) override fun createSocket(address: InetAddress?, port: Int, localAddress: InetAddress?, localPort: Int): Socket = delegate.createSocket(address, port, localAddress, localPort).let(this::patch) override fun getSupportedCipherSuites(): Array<String> = delegate.supportedCipherSuites private fun patch(s: Socket): Socket = s.apply { if (this is SSLSocket) enabledProtocols = arrayOf("TLSv1.2") } } Enable TLS 1.2 https://github.com/square/okhttp/issues/2372
class TlsSocketFactory(private val delegate: SSLSocketFactory) : SSLSocketFactory() { override fun
getDefaultCipherSuites(): Array<String> = delegate.defaultCipherSuites override fun createSocket(s: Socket?, host: String?, port: Int, autoClose: Boolean): Socket = delegate.createSocket(s, host, port, autoClose).let(this::patch) override fun createSocket(host: String?, port: Int): Socket = delegate.createSocket(host, port).let(this::patch) override fun createSocket(host: String?, port: Int, localHost: InetAddress?, localPort: Int): Socket = delegate.createSocket(host, port, localHost, localPort).let(this::patch) override fun createSocket(host: InetAddress?, port: Int): Socket = delegate.createSocket(host, port).let(this::patch) override fun createSocket(address: InetAddress?, port: Int, localAddress: InetAddress?, localPort: Int): Socket = delegate.createSocket(address, port, localAddress, localPort).let(this::patch) override fun getSupportedCipherSuites(): Array<String> = delegate.supportedCipherSuites private fun patch(s: Socket): Socket = s.apply { if (this is SSLSocket) enabledProtocols = arrayOf("TLSv1.2") } } Enable TLS 1.2 SSLSocketFactoryΛϥοϓͯ͠TLS 1.2Λ༗ޮʹ͢Δ https://github.com/square/okhttp/issues/2372
None
FRESH!
FRESH!
‣ ଈ࠲ʹαʔόʔ͔Βใ͕ඈΜͰ͖ͯ࠷ߴ ‣ ίωΫγϣϯʹؾΛΔඞཁ͕͋Δ ‣ HTTP/1.1ʹແ͔ͬͨ֓೦ͳͷͰ׳ΕΔ·Ͱେม ‣ AndroidͰϓϩμΫγϣϯʹಋೖ͕ͨ͠গͳ͍ ‣ ࢼߦࡨޡͷ࿈ଓ
Conclusion
Thank you