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
ローカルLLMでどこまでコードが書けるか -縮小版 / How much code can be written on a local LLM Shortened
kishida
2
190
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
170
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
180
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
860
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
950
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.5k
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
Prismを使った型安全な暗号化_関数型まつり2026
_fhhmm
0
140
yield再入門 #phpcon
o0h
PRO
0
470
作るコストが小さくなった時代 幸せに働くために改めて考えたいこと 〜エンジニアとして価値を出し続けるために注視している二分野〜
yuppeeng
0
100
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
2.6k
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
How to train your dragon (web standard)
notwaldorf
97
6.7k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
390
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
240
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
490
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
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