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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
560
GitのCLI操作を楽にするためにエイリアスを作った話
nojiri1098
0
330
Other Decks in Programming
See All in Programming
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
新卒PdEのリアル
ryu1013
1
490
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
140
業務時間外もAIに働いてもらう話
colorful12
3
10k
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
850
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
230
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
120
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
130
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
320
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
230
Featured
See All Featured
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
290
A Modern Web Designer's Workflow
chriscoyier
699
190k
Why Our Code Smells
bkeepers
PRO
340
58k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
Designing Experiences People Love
moore
143
24k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Building an army of robots
kneath
306
46k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Skip the Path - Find Your Career Trail
mkilby
1
230
Designing for humans not robots
tammielis
254
26k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
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ϑΝΠϧΛॻ͍ͯΠϯλʔϑΣʔεΛ ɹੜ͢Δ ˠੜ͞ΕͨΠϯλʔϑΣʔεΛ࣮ͬͯ͢Δ