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
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
230
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
140
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
330
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
130
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
190
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
130
信頼性について考えてみる(SRE NEXT 2026 miniLT)
hayama17
0
190
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
320
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.9k
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.5k
えっ!!コードを読まずに開発を!?
hananouchi
0
220
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.2k
The Curse of the Amulet
leimatthew05
2
13k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
280
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
210
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
420
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
360
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
How to build a perfect <img>
jonoalderson
1
5.8k
Context Engineering - Making Every Token Count
addyosmani
9
1k
The Cult of Friendly URLs
andyhume
79
6.9k
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