Upgrade to Pro — share decks privately, control downloads, hide ads and more …

gRPCとSwift (導入編)

gRPCとSwift (導入編)

CA.Swift #5
2017.01.25

956acd73b3fce78c10553b0b082a1cb7?s=128

shinji hayashi

January 26, 2018
Tweet

Transcript

  1. H31$ͱ4XJGU ಋೖฤ ྛɹᚸ࢘ $"4XJGU

  2. ྛɹᚸ࢘ (JU)VCTIJO ೥৽ଔೖࣾɻגࣜձࣾͷJ04ΤϯδχΞΛܦͯɺ ݱࡏ͸461&3$)0*$&ͷJ04Λ୲౰ɻ ࣗݾ঺հ

  3. None
  4. H31$

  5. H31$ 31$Λ࣮ݱ͢ΔͨΊ(PPHMF͕։ൃͨ͠ϑϨʔϜϫʔΫ 1SPUPDPM#V⒎FSTʹΑΓ σʔλͷγϦΞϥΠζɾαʔϏεΠϯλʔϑΣΠεΛఆٛ ଟݴޠରԠ $ +BWB (P 0CKFDUJWF$FUDʣ

  6. HSQDTXJGU

  7. ೥݄ʙɹެ։ 31$Λ(PPHMF͕4XJGUͰ࡞੒ IUUQTHJUIVCDPNHSQDHSQDTXJGU HSQDTXJGU

  8. 4XJGU4VNNJU4BO'SBODJTDP IUUQTXXXTMJEFTIBSFOFUUJNCVSLTGBTUBOESFMJBCMFTXJGUBQJTXJUIHSQD HSQDTXJGU

  9. 1SPUPDPM#V⒎FST

  10. 1SPUPDPM#V⒎FST (PPHMF͕։ൃ͍ͯ͠ΔγϦΞϥΠζϑΥʔϚοτ ɾQSPUPϑΝΠϧʹΑΔΫϥεఆٛ ɾςΩετͰ͸ͳ͘όΠφϦʹม׵ ɾܕ৘ใ͕͋ΔͨΊ҆શ

  11. ͍ܰ Մಡੑ Մಡੑ 1SPUPDPM#V⒎FST +40/ ϝϦοτ σϝϦοτ ಋೖखॱ͕ෳࡶ ίϯύΠϧ͕ඞཁ σʔλͷղੳॲཧ͕ෳࡶ

    ૣ͍ ௨৴ ҆શ Ұൠత σʔλྔ͕େྔ ؀ڥ σόοά 1SPUPDPM#V⒎FSTɾ+40/
  12. ͦ΋ͦ΋31$

  13. ϓϩάϥϜ͔ΒผͷΞυϨεۭؒʹ͋Δ αϒϧʔνϯ΍खଓ͖Λ࣮ߦ͢Δ͜ͱΛՄೳʹ͢Δٕज़ GVODUJPO ΫϥΠΞϯτ αʔόʔ ొ࿥ ొ࿥ GVODUJPO ࡞ۀՕॴ 31$ϥΠϒϥϦɾϑϨʔϜϫʔΫ

    31$ 31$3FNPUF1SPDFEVSF$BMMԕִखଓ͖ݺͼग़͠
  14. H31$

  15. H31$ )551ͷ࢓༷ʹଇͬͨܗͰछྨͷ௨৴ํࣜΛఏڙ IUUQTHSQDJPEPDTHVJEFTDPODFQUTIUNM

  16. 6OBSZ31$T ͭͷϦΫΤετʹରͯͭ͠ͷϨεϙϯεΛฦ͢ํࣜ 3FRVFTU $MJFOU 3FTQPODF ҰൠతͳϚΠΫϩαʔϏεͳͲ ༻్ H31$ 4FSWFS

  17. 4FSWFS4USFBNJOH31$T ͭͷϦΫΤετʹରͯ͠ෳ਺ͷϨεϙϯεΛฦ͢ํࣜ 3FRVFTU $MJFOU 3FTQPODF αʔόαΠυϓογϡ λΠϜϥΠϯ ϑΟʔυ഑৴ͳͲ ༻్ H31$

    3FTQPODF 3FTQPODF 4FSWFS
  18. $MJFOU4USFBNJOH31$T ෳ਺ͷϦΫΤετʹରͯͭ͠ͷϨεϙϯεΛฦ͢ํࣜ 3FRVFTU 3FTQPODF େྔͷσʔλΞοϓϩʔυͳͲ ༻్ H31$ 4FSWFS 3FRVFTU 3FRVFTU

    $MJFOU
  19. #JEJSFDUJPOBM4USFBNJOH31$T ෳ਺ͷϦΫΤετʹରͯ͠ෳ਺ͷϨεϙϯεΛฦ͢ํࣜ νϟοτͳͲ૒ํ޲௨৴Λߦ͏ͳͲ ༻్ H31$ 4FSWFS 3FRVFTU 3FTQPODF 3FTQPODF 3FRVFTU

    $MJFOU
  20. ɾ*%-͕ͦͷ··ΠϯλʔϑΣΠευΩϡϝϯτ ɾαʔόʔɾΫϥΠΞϯτʹඞཁͳίʔυͷࣗಈੜ੒ ɾ1SPUPDPM#V⒎FSTʹΑΓܕอূ͕͞ΕΔ H31$

  21. HSQDHBUFXBZ

  22. QSPUPCVGఆ͔ٛΒ3&45"1*Λఏڙ͢ΔϦόʔεϓϩΩγΛੜ੒ ௨ৗ௨ΓH31$Ͱߏஙͨ͠αʔόʹ3&45ܦ༝ͰͷΞΫηε΋Մೳ HSQDHBUFXBZ

  23. 1SPUPDPM#V⒎FST ಋೖ

  24. ಋೖ TXJGUQSPUPCVG HJUDMPOFIUUQTHJUIVCDPNBQQMFTXJGUQSPUPCVGHJU DETXJGUQSPUPCVG TXJGUCVJME QSPUPDHFOTXJGU͕࡞ΒΕΔ

  25. ಋೖ TBNQMFQSPUP syntax = "proto3" message Info { int64 id

    = 1 string title = 2 }
  26. CSFXJOTUBMMQSPUPCVG QSPUPDTXJGU@PVUTBNQMFQSPUP MT TBNQMFQCTXJGUTBNQMFQSPUP IUUQTTQFBLFSEFDLDPNLZPIFJHQSPUPDPMCV⒎FST ิ଍ ϓϥάΠϯͷ1"5)Λ௨͓ͯ͘͠ͱศརͰ͢ɻ QSPUPDTXJGU@PVUʻग़ྗઌσΟϨΫτϦʼʻೖྗϑΝΠϧʼ ಋೖ TXJGUQSPUPCVG

  27. H31$ ಋೖ

  28. ಋೖ TBNQMFQSPUP CSFXJOTUBMMQSPUPCVG HJUDMPOFIUUQTHJUIVCDPNHSQDHSQDTXJGUHJU DEHSQDTXJGUQMVHJO NBLF QSPUPDHFOTXJGUQSPUPDHFOTXJGUHSQD͕࡞ΒΕΔ

  29. ಋೖ FDIPQSPUP syntax = "proto3"; package echo; service Echo {

    rpc Get(EchoRequest) returns (EchoResponse) {} rpc Expand(EchoRequest) returns (stream EchoResponse) {} rpc Collect(stream EchoRequest) returns (EchoResponse) {} rpc Update(stream EchoRequest) returns (stream EchoResponse) {} } message EchoRequest { // The text of a message to be echoed. string text = 1; } message EchoResponse { // The text of an echo response. string text = 1; }
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 #VJME4FUUJOHT಺ 4ZTUFN)FBEFS4FBSDI1BUITͱ4ZTUFN'SBNFXPSL4FBSDI1BUITʹ ʢ$H31$Ͱͷ໰୊ͷΑ͏ͳͷͰ͍ͣΕվળ͞ΕΔ͔΋ʣ Λ௥Ճ XIFSFZPVDMPOFUIFHSDQTXJGUHJUHSQDTXJGU4PVSDFT$H31$JODMVEF

  38. ಋೖ ࣗ෼ͷϓδΣΫτʹೖΕΔ৔߹ 4XJGU(31$YDPEFQSPK಺ͷUBSHFUT͔Β[MJCFYBNQMFΛ࡟আ Ϗϧυ͕௨ΔΑ͏ʹͳΔ

  39. த਎

  40. FDIPQSPUP syntax = "proto3"; package echo; service Echo { rpc

    Get(EchoRequest) returns (EchoResponse) {} rpc Expand(EchoRequest) returns (stream EchoResponse) {} rpc Collect(stream EchoRequest) returns (EchoResponse) {} rpc Update(stream EchoRequest) returns (stream EchoResponse) {} } message EchoRequest { // The text of a message to be echoed. string text = 1; } message EchoResponse { // The text of an echo response. string text = 1; }
  41. FDIPQSPUP syntax = "proto3"; package echo; service Echo { rpc

    Get(EchoRequest) returns (EchoResponse) {} rpc Expand(EchoRequest) returns (stream EchoResponse) {} ← serverStreaming rpc Collect(stream EchoRequest) returns (EchoResponse) {} ← clientStreaming rpc Update(stream EchoRequest) returns (stream EchoResponse) {} ← bidirectionalStreaming } message EchoRequest { // The text of a message to be echoed. string text = 1; } message EchoResponse { // The text of an echo response. string text = 1; } ← unaryStreaming
  42. FDIPQSPUP syntax = "proto3"; package echo; service Echo { rpc

    Get(EchoRequest) returns (EchoResponse) {} rpc Expand(EchoRequest) returns (stream EchoResponse) {} rpc Collect(stream EchoRequest) returns (EchoResponse) {} rpc Update(stream EchoRequest) returns (stream EchoResponse) {} } message EchoRequest { // The text of a message to be echoed. string text = 1; } message EchoResponse { // The text of an echo response. string text = 1; } ϦΫΤετϝοηʔδ Ϩεϙϯεϝοηʔδ ϝιουఆٛ ϝοηʔδ ఆٛ αʔϏεఆٛ
  43. FDIPQCTXJGU

  44. FDIPHSQDTXJGU

  45. FDIPHSQDTXJGU

  46. &DIP7JFX$POUSPMMFSTXJGU . . . . . .

  47. H31$ ࣮૷ෛ୲ͷܰݮ ؅ཧͷෛ୲ݮ αʔόʔɾΫϥΠΞϯτͷίʔυࣗಈੜ੒ )551̎ʹΑΔ௨৴ QSPUPϑΝΠϧʹΑͬͯΠϯλʔϑΣʔεఆٛɾ࢓༷ FUD

  48. HSQDHBUFXBZ͕ඞཁʹͳΔ৔໘ H31$ ϑϨʔϜϫʔΫͷ੒ख़౓ υΩϡϝϯτྔ ಋೖɾֶशίετ νʔϜ಺ͰͷϫʔΫϑϩʔ ઈࢍ։ൃதɾมߋ఺ʹ஫ҙ ՝୊ ࣮૷ෛ୲ͷܰݮ ؅ཧͷෛ୲ݮ

    αʔόʔɾΫϥΠΞϯτͷίʔυࣗಈੜ੒ )551̎ʹΑΔ௨৴ QSPUPϑΝΠϧʹΑͬͯΠϯλʔϑΣʔεఆٛɾ࢓༷ FUD
  49. 5IBOL:PV