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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
920
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.4k
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
230
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
2
700
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.5k
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
390
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
740
dRuby over BLE
makicamel
2
390
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
170
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
200
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
500
Making Projects Easy
brettharned
120
6.7k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Designing for Performance
lara
611
70k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Docker and Python
trallard
47
3.9k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
66
55k
Abbi's Birthday
coloredviolet
3
8.2k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Building Adaptive Systems
keathley
44
3.1k
Code Reviewing Like a Champion
maltzj
528
40k
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