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

Evans: more expressive gRPC client

ktr
February 20, 2018

Evans: more expressive gRPC client

ktr

February 20, 2018
Tweet

More Decks by ktr

Other Decks in Programming

Transcript

  1. at Go 1.10 Release Party in Tokyo more expressive gRPC

    client Evans
  2. XIPBNJ !cJE [email protected]  ձ௡େֶֶ෦೥ ιϥϛπגࣜձࣾαʔόΤϯδχΞ

  3. at Go 1.10 Release Party in Tokyo more expressive gRPC

    client Evans
  4. None
  5. ΞδΣϯμ w H31$ͱΫϥΠΞϯτπʔϧ܈ w &WBOTͱ&WBOT͕໨ࢦͨ͠΋ͷ w &WBOTͷΞʔΩςΫνϟͱ࣮૷

  6. H31$

  7. gRPC DMJFOUTFSWFSؒͰಁաతʹ௨৴Ͱ͖ΔγεςϜΛ ߏங͢ΔͨΊͷ31$ϑϨʔϜϫʔΫ

  8. gRPC *%-Ͱ"1*εΩʔϚΛఆٛ͢Δ ΫϥΠΞϯταʔόͷίʔυΛੜ੒͢Δ αʔόͷϩδοΫΛ࣮૷͢Δ

  9. H31$3FNPUF1SPDFEVSF$BMMT PGDPVSTF IUUQTHSQDJPGBR

  10. None
  11. gRPC ͷྑ͍ͱ͜Ζ w"1*࢓༷ͱ࣮૷ͷဃ཭Λ๷͙͜ͱ͕Ͱ͖Δ wΫϥΠΞϯταʔόؒͷ*'͕෗ഊ͠ͳ͍ w4USFBNJOH31$ wFUD

  12. gRPC ͷͭΒ͍ͱ͜Ζ w)551͔͠αϙʔτ͍ͯ͠ͳ͍ wπʔϧɾϛυϧ΢ΣΞ܈͕ॆ࣮͍ͯ͠ͳ͍ w"1*ͷσόοά͕ͮ͠Β͍

  13. gRPC ͷͭΒ͍ͱ͜Ζ w)551͔͠αϙʔτ͍ͯ͠ͳ͍ wπʔϧɾϛυϧ΢ΣΞ܈͕ॆ࣮͍ͯ͠ͳ͍ w"1*ͷσόοά͕ͮ͠Β͍

  14. API ͷσόοά͕ͮ͠Β͍ wH31$͸σʔλΛγϦΞϥΠζͯ͠΍ΓͱΓ͢Δ wDVSM΍XHFU౳ͰςετͰ͖ͳ͍ wΫϥΠΞϯτίʔυΛ࣮૷͢ΔPSπʔϧͷར༻

  15. grpc-ecosystem / polyglot w "'"*, ࠷΋ߴػೳͳΫϥΠΞϯτ w+BWB੡ wͨ͘͞ΜͷΦϓγϣϯΛίϚϯυϥΠϯͰࢦఆ͢ Δඞཁ͕͋ͬͯ൥ࡶ

  16. grpc-ecosystem / polyglot 1 $ echo <json-request> | java -jar

    polyglot.jar \ 2 --command=call \ 3 --endpoint=<host>:<port> \ 4 --full_method=<some.package.Service/doSomething> \ 5 --proto_discovery_root=<path>
  17. njpatel / grpcc w/PEFKT੡ w3&1-PS$-*Ͱͷ࣮ߦ͕Մೳ w3&1-Ͱ+BWB4DSJQUΛॻ͘ඞཁ͕͋Δ wิ׬͕ͳ͍

  18. njpatel / grpcc

  19. ͍·͍ͪͬ͘͠Γ͜ͳ͍

  20. ސ٬ ͕ຊ౰ʹཉ͔ͬͨ͠΋ͷ

  21. ސ٬ ͕ຊ౰ʹཉ͔ͬͨ͠΋ͷ ָʹςετͰ͖ΔΫϥΠΞϯτ

  22. Ұ͔Βͭ͘Δͧ

  23. LUSFWBOT

  24. ktr0731 / evans w(P੡ wָʹ͔ͭ͑ΔΫϥΠΞϯτ w1SPUPDPM#V⒎FST

  25. Ϣʔεέʔε wσόοά ɺςετ wγΣϧεΫϦϓτ΁ͷ૊ΈࠐΈ

  26. σόοάɺςετ wجຊతʹखಈͰ"1*Λୟ͘ wͰ͖Δ͚ͩλΠϓͨ͘͠ͳ͍ w๛෋ͳิ׬͕ཉ͍͠ wෳ਺ͷ"1*Λୟ͖͍ͨ৔߹΋͋Δ

  27. γΣϧεΫϦϓτ΁ͷ૊ΈࠐΈ wTUEJOPSpMFTUEPVU w૊ΈࠐΈ΍͍͢ΠϯλʔϑΣʔε͕ඞཁ

  28. Ϣʔεέʔε wσόοά ɺςετ 3&1-Ϟʔυ wγΣϧεΫϦϓτ΁ͷ૊ΈࠐΈ ίϚϯυϥΠϯϞʔυ

  29. EFNP LUSFWBOTEFNP

  30. None
  31. None
  32. Evans Internal w εΩʔϚͷϩʔυ w &WBOTͷϞσϧ΁ͷม׵ w 31$ͷൃߦ $-*Ϟʔυ PS

    3&1-ͷىಈ 3&1-Ϟʔυ
  33. DBTF3&1-31$DBMM

  34. εΩʔϚͷϩʔυ 1 func runProtoc(args []string) ([]byte, error) { 2 buf,

    errBuf := new(bytes.Buffer), new(bytes.Buffer) 3 4 // with "--descriptor_set_out=/dev/stdout" 5 cmd := exec.Command("protoc", args...) 6 cmd.Stdout = buf 7 cmd.Stderr = errBuf 8 if err := cmd.Run(); err != nil { 9 if errBuf.Len() != 0 { 10 return nil, errors.New(errBuf.String()) 11 } 12 return nil, err 13 } 14 return buf.Bytes(), nil 15 }
  35. wHPMBOHQSPUPCVGEFTDSJQUPS wHPMBOHQSPUPCVGQSPUP εΩʔϚͷϩʔυ 1 code, _ := runProtoc(args) 2 ds

    := descriptor.FileDescriptorSet{} 3 proto.Unmarshal(code, &ds)
  36. Ϟσϧ΁ͷม׵ wΞϓϦέʔγϣϯ͔Βѻ͍΍͘͢͢ΔͨΊ wKIVNQQSPUPSFqFDU΁ͷґଘΛͳͨ͘͢Ί ޙड़

  37. REPL: read wDCBUBHPQSPNQU

  38. REPL: read / eval wϑΟʔϧυΛ࠶ؼతʹḷΔ wϓϦϛςΟϒܕͰ͋Ε͹஋Λೖྗͤ͞Δ

  39. 1 message User { 2 string first_name = 1; 3

    string last_name = 2; 4 Gender gender = 3; 5 } 6 7 message RegisterUsersRequest { 8 repeated User users = 1; 9 } type = "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | "bytes" | messageType | enumType
  40. 1 message User { 2 string first_name = 1; 3

    string last_name = 2; 4 Gender gender = 3; 5 } 6 7 message RegisterUsersRequest { 8 repeated User users = 1; 9 } type = "double" | "float" | "int32" | "int64" | "uint32" | "uint64" | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | "bytes" | messageType | enumType
  41. type = "double" | "float" | "int32" | "int64" |

    "uint32" | "uint64" | "sint32" | "sint64" | "fixed32" | "fixed64" | "sfixed32" | "sfixed64" | "bool" | "string" | "bytes" | messageType | enumType 1 message User { 2 string first_name = 1; 3 string last_name = 2; 4 Gender gender = 3; 5 } 6 7 message RegisterUsersRequest { 8 repeated User users = 1; 9 }
  42. ϓϦϛςΟϒܕͷೖྗ wೖྗΛड͚͚ͭΔ DCBUBHPQSPNQU  wରԠ͢Δܕ΁ม׵ wϑΟʔϧυʹ஋Ληοτ͢Δ KIVNQQSPUPSFqFDU  wೖྗର৅ͷϝοηʔδ͸ಈతʹܾఆ͞ΕΔ

  43. ϝοηʔδͷಈతͳߏங wKIVNQQSPUPSFqFDUEZOBNJD.FTTBHF wQSPUP.BSTIBMFS࣮૷Λ࣋ͭ

  44. ϝοηʔδͷಈతͳߏங ֤ϑΟʔϧυ஋ΛEZOBNJD.FTTBHF͕อ࣋ #V⒎FS.BSTIBM΁QSPUP.FTTBHFͱͯ͠౉͞ΕΔ .BSTIBM͕QSPUP.BSTIBMFSͷ࣮૷ΛݺͿ EZOBNJD.FTTBHF.BSTIBMʹΑΓγϦΞϥΠζ

  45. QSPUP.FTTBHF QSPUP.BSTIBMFS EZOBNJD.FTTBHF Marshal() ([]byte, error) CVG WBMVFT encode marshal

    each field values ϝοηʔδͷಈతͳߏங
  46. ΞʔΩςΫνϟ w $MFBO"SDIJUFDUVSF w )FYBHPOBM"SDIJUFDUVSF

  47. ͳͥ CA / HA ͔ʁ w ࠜװΛࢧ͑ΔϥΠϒϥϦ͕ະ੒ख़ w $-*Ϟʔυɺ3&1-Ϟʔυ͕͋Δ w

    ίϯϙʔωϯτ͕ଟ͍
  48. JOQVUUFS*' 3&1- 1SPNQU*OQVUUFS DCBUBHPQSPNQU $-* +40/JOQVUUFS FODPEJOHKTPO Entity layer Adapter

    layer UseCase layer EFTDSJQUPST KIVNQQSPUPSFqFDU pFMET NFTTBHF  TFSWJDF*'
  49. TODOs w ετϦʔϜछ w 5-4ରԠ w ϦϑϨΫγϣϯαʔόରԠ w FUD

  50. TODOs w ετϦʔϜछ w 5-4ରԠ w ϦϑϨΫγϣϯαʔόରԠ w FUD 1VMM3FRVFTUT*TTVFT

    XFMDPNF
  51. ·ͱΊ w ݸਓతʹ͸ ָʹ͔ͭ͑ΔΫϥΠΞϯτ͕Ͱ͖ͨ w ڊਓͷݞʹ৐͍ͬͯΔ͓͔͛Ͱ͢ w ͱ͸͍͑50%0͸·ͩଟ͍

  52. ·ͱΊ w ݸਓతʹ͸ ָʹ͔ͭ͑ΔΫϥΠΞϯτ͕Ͱ͖ͨ w ڊਓͷݞʹ৐͍ͬͯΔ͓͔͛Ͱ͢ w ͱ͸͍͑50%0͸·ͩଟ͍ ΍͍ͬͯͧ͘ʂʂ