Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
イメージで理解するgRPC
Search
Daiki Nojiri
May 23, 2020
Programming
380
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
イメージで理解するgRPC
Daiki Nojiri
May 23, 2020
More Decks by Daiki Nojiri
See All by Daiki Nojiri
今日から書けるリーダブルコード
nojiri1098
0
600
GitのCLI操作を楽にするためにエイリアスを作った話
nojiri1098
0
330
Other Decks in Programming
See All in Programming
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
2
330
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
380
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
Railsバージョンを4倍にした話
optim
0
420
contenteditable と日本語入力に向き合う
colorful12
0
200
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.6k
Domain-Driven Transformation
hschwentner
2
2.3k
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
JIS keyboard support in Omarchy
lef237
0
120
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
My Coaching Mixtape
mlcsv
0
360
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
620
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Transcript
ΠϝʔδͰཧղ͢Δ
ࠓͷΰʔϧ ɾH31$ͬͯͳʹʁ ɾ31$ͬͯͳʹʁ ɾͲ͏࣮ͬͯ͢Δͷʁ
ͬͯͳʹʁ
H31$ (PPHMF͕࡞ͬͨ31$ϑϨʔϜϫʔΫ
31$ͬͯͳʹʁ
31$ 3FNPUF1SPDFEVSF$BMM
31$ DMJFOU͕ࣗͷϝιουΛ࣮ߦ͢Δײ֮Ͱ TFSWFS্ͷϝιουΛ࣮ߦͰ͖Δ͘͠Έ
ͭ·ΓɺͲ͏͍͏͜ͱʁ
DMJFOUͱTFSWFSʹಉ໊ϝιου͕͋ͬͯ IUUQTJDPOTDPNJDPOTTFUTFSWFS DMJFOU TFSWFS Find() Find()
DMJFOU͕ϝιουΛ࣮ߦ͢Δͱ DMJFOU TFSWFS Find() Find() IUUQTJDPOTDPNJDPOTTFUTFSWFS
TFSWFSଆͷಉ໊ϝιου͕࣮ߦ͞Ε DMJFOU TFSWFS Find() Find() SFRVFTU IUUQTJDPOTDPNJDPOTTFUTFSWFS
ͦͷฦΓ͕DMJFOUଆͷฦΓʹͳΔ DMJFOU TFSWFS Find() Find() SFRVFTU SFTQPOTF IUUQTJDPOTDPNJDPOTTFUTFSWFS
H31$͜ͷؒΛ͏·ͬͯ͘͘ΕΔ DMJFOU TFSWFS Find() Find() SFRVFTU SFTQPOTF IUUQTJDPOTDPNJDPOTTFUTFSWFS
const res = axios.get("/api/v1/users/1") js req := FindRequest({ID: 1}) res,
err = user.Find(req) go 3&45 31$ ͜Μͳ͍ํ͕Ͱ͖·͢
Ͳ͏࣮ͬͯ͢Δͷʁ
31$Λ࣮ݱ͢Δʹ SFRVFTU DMJFOU TFSWFS SFTQPOTF IUUQTJDPOTDPNJDPOTTFUTFSWFS
ڞ௨ೝ͕ࣝඞཁ SFRVFTU DMJFOU TFSWFS SFTQPOTF ϝιουͷ໊લ ϦΫΤετͷܗࣜ Ϩεϙϯεͷܗࣜ IUUQTJDPOTDPNJDPOTTFUTFSWFS
ͦΕ͕ɺQSPUPϑΝΠϧ SFRVFTU DMJFOU TFSWFS SFTQPOTF QSPUP IUUQTJDPOTDPNJDPOTTFUTFSWFS
QSPUPϑΝΠϧͷྫ service User { rpc Find(FindRequest) returns (FindResponse) {} }
message FindRequest { int32 id = 1; } message FindResponse { string name = 1; } user_service.proto
QSPUPϑΝΠϧͷྫ user_service.proto ϦΫΤετͷܗࣜ Ϩεϙϯεͷܗࣜ service User { rpc Find(FindRequest) returns
(FindResponse) {} } message FindRequest { int32 id = 1; } message FindResponse { string name = 1; }
service User { rpc Find(FindRequest) returns (FindResponse) {} } message
FindRequest { int32 id = 1; } message FindResponse { string name = 1; } QSPUPϑΝΠϧͷྫ user_service.proto ˢϝιουͷఆٛ
QSPUP QCHP ࣍ʹɺΠϯλʔϑΣʔεΛੜ͢Δ QSPUPD QSPUPDΠϯλʔϑΣʔεΛੜ͢ΔͨΊͷίϚϯυ
QSPUP QCHP ࣍ʹɺΠϯλʔϑΣʔεΛੜ͢Δ QSPUPD ͍ΖΜͳJOUFSGBDFGVOD͕ࣗಈੜ ͞ΕΔɽਓҰ͍͡Βͳ͍
ॏཁͳ෦͚ͩϐοΫΞοϓ type UserServer interface { Find( context.Context, *FindRequest ) (*FindResponse,
error) } user_service.pb.go αʔόଆͷΠϯλʔϑΣʔε αʔόଆ͜Εʹ߹ΘͤͯϝιουΛ࣮͢Δ
ॏཁͳ෦͚ͩϐοΫΞοϓ type UserClient interface { Find( ctx context.Context, in *FindRequest,
opts ...grpc.CallOption ) (*FindResponse, error) } ΫϥΠΞϯτଆͷΠϯλʔϑΣʔε ΫϥΠΞϯτଆ͜Εʹ߹ΘͤͯϝιουΛ͏ user_service.pb.go
ॏཁͳ෦͚ͩϐοΫΞοϓ func (c *userClient) Find( ctx context.Context, in *FindRequest, opts
...grpc.CallOption ) (*FindResponse, error) { out := new(FindResponse) err := c.cc.Invoke( ctx, "/user_service.User/Find", in, out, opts... ) if err != nil { return nil, err } return out, nil } ΫϥΠΞϯτଆͷϝιου ΫϥΠΞϯτଆ͕ݺͼग़͢ϝιου࣮ࡁΈ user_service.pb.go
QSPUP QCHP ͪͳΈʹɺෳݴޠʹରԠ͍ͯ͠Δ SC KBWB
αʔόଆͷ͍ํ ؆ུ൛ import pb "path/to/pb.go" type server struct{} func (s
*server) Find( ctx context.Context, in *pb.FindRequest ) (*pb.FindResponse, error) { user := db.Find(&user) out := &pb.FindResponse{name: user.name} return out, nil } s := grpc.NewServer() pb.RegisterUserServer(s, &server{}) s.Serve(lis) server/main.go
import pb "path/to/pb.go" type server struct{} func (s *server) Find(
ctx context.Context, in *pb.FindRequest ) (*pb.FindResponse, error) { user := db.Find(&user) out := &pb.FindResponse{name: user.name} return out, nil } s := grpc.NewServer() pb.RegisterUserServer(s, &server{}) s.Serve(lis) αʔόଆͷ͍ํ ؆ུ൛ server/main.go %#͔ΒΛ औಘͯ͠ฦ͢ αʔόͷ্ཱͪ͛
ΫϥΠΞϯτଆͷ͍ํ ؆ུ൛ import pb "path/to/pb.go" c := pb.NewUserClient(conn) req :=
&pb.FindRequest{ id: 1, } resp, err := c.Find(context.Background(), req) if err != nil { log.Fatal(err) } log.Println("Name: ", resp.name) // #=> Name: alice client/main.go
ΫϥΠΞϯτଆͷ͍ํ ؆ུ൛ import pb "path/to/pb.go" c := pb.NewUserClient(conn) req :=
&pb.FindRequest{ Name: "alice", } resp, err := c.Find(context.Background(), req) if err != nil { log.Fatal(err) } log.Println("Name: ", resp.name) // #=> Name: alice client/main.go αʔόଆͷFind()ͷฦΓ
ࠓͷ·ͱΊ H31$ͬͯͳʹʁ ˠ(PPHMF͕࡞ͬͨ31$ϑϨʔϜϫʔΫ 31$ͬͯͳʹʁ ˠΫϥΠΞϯτ͔ΒαʔόͷϝιουΛݺͿ H31$Λ͏ʹʁ ˠQSPUPϑΝΠϧΛॻ͍ͯΠϯλʔϑΣʔεΛ ɹੜ͢Δ ˠੜ͞ΕͨΠϯλʔϑΣʔεΛ࣮ͬͯ͢Δ