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

DroidKaigi 2018 gRPC/Protobuf

k-mats
February 07, 2018
5.6k

DroidKaigi 2018 gRPC/Protobuf

k-mats

February 07, 2018
Tweet

Transcript

  1. H31$ͱ1SPUPDPM#V⒎FSTͰ
    Ұຯҧ͏"OESPJE௨৴
    Kohei Matsumoto
    @ DroidKaigi 2018

    View full-size slide

  2. Kohei Matsumoto
    Android/iOS Developer
    Twitter: kmats_
    Github: k-mats

    View full-size slide

  3. Outline
    • RPC ͱ͸
    • gRPC ͱ͸
    • Protocol Buffers ͱ͸
    • gRPC + Protocol Buffers ͷಋೖ
    • ։ൃ্ͷ޻෉
    • protoϑΝΠϧͷڞ༗ํ๏ͷྫ

    View full-size slide

  4. RPC?
    REST -> JSON?
    RPC -> XML?

    View full-size slide

  5. RPC?
    REST -> JSON?
    RPC -> XML?

    View full-size slide

  6. RPC
    > Remote procedure call is the synchronous
    language-level transfer of control between
    programs in disjoint address spaces whose
    primary communication medium is a narrow
    channel.
    ଞͷΞυϨεۭؒʢe.g. ωοτϫʔΫ্ͷαʔόʣʹ͋ΔॲཧΛ
    ࣮ߦ͢Δ͜ͱɻ
    Bruce Jay Nelson. 1981. Remote Procedure Call. Ph.D. Dissertation.
    Carnegie Mellon Univ., Pittsburgh, PA, USA. AAI8204168.
    https://dl.acm.org/citation.cfm?id=910306

    View full-size slide

  7. RPC as HTTP API
    APIͷઃܭํ਑ σʔλͷදݱܗࣜ
    JSON, XML,
    Protocol Buffers, …
    REST, RPC, …

    View full-size slide

  8. RPC as HTTP API
    σʔλͷදݱܗࣜ
    JSON, XML,
    Protocol Buffers, …
    REST, RPC, …
    APIͷઃܭํ਑

    View full-size slide

  9. REST vs RPC as HTTP API
    • ҧ͍ͷ1ͭ:ʮAPIઃܭ࣌ʹͲ͜ʹண໨͢Δ͔ʯ
    • Ϧιʔεʢૢ࡞ର৅ʣͱΞΫγϣϯʢૢ࡞ํ
    ๏ʣΛͲ͏΍ͬͯදݱ͢Δ͔
    • REST: ϦιʔεΛத৺ʹߟ͑Δ
    • RPC: ΞΫγϣϯΛத৺ʹߟ͑Δ

    View full-size slide

  10. RESTͷํ͕޲͍͍ͯΔέʔε
    • e.g. ϒϩάαʔϏεͷAPI
    • APIͷओͳ໾ׂ͸ϒϩάهࣄʹରͯ͠CRUD
    ૢ࡞Λ͢Δ͜ͱ
    • هࣄͱ͍͏ϦιʔεΛத৺ʹߟ͑ͨํ͕ྑ͍
    • ΞΫγϣϯ͸HTTPϝιουͰදݱ
    https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/

    View full-size slide

  11. ϒϩάAPI: RESTͷ৔߹
    • Create:
    • POST https://example.com/api/articles
    • body: {“title”: “New post”, “author”: “John”, “description”: “…”}
    • Read:
    • GET https://example.com/api/articles/123
    • Update:
    • PATCH https://example.com/api/articles/123
    • body: {“title”: “Revised”}
    • Delete:
    • DELETE https://example.com/api/articles/123
    https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/

    View full-size slide

  12. ϒϩάAPI: RPCͷ৔߹
    • Create:
    • https://example.com/api/createArticle
    • body: {“title”: “New post”, “author”: “John”, “description”: “…”}
    • Read:
    • https://example.com/api/getArticle
    • Update:
    • https://example.com/api/updateArticle
    • body: {“article_id”: 123, “title”: “Revised”}
    • Delete:
    • https://example.com/api/deleteArticle
    https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/

    View full-size slide

  13. RPCͷํ͕޲͍͍ͯΔέʔε
    • e.g. SlackͷΑ͏ͳνϟοταʔϏεͷAPI
    • APIΛ௨ͯ͡ҎԼͷػೳΛఏڙ͍ͨ͠ͱ͢Δ
    • ͋Δνϟϯωϧʹ͍ΔϢʔβ͕νϟϯωϧ͔Βୀग़
    ͢Δ (leave)
    • ͋Δνϟϯωϧʹ͍ΔϢʔβΛνϟϯωϧ͔Β௥͍
    ग़͠ɺ࠶ࢀՃΛې͡Δʢkickʣ
    https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/

    View full-size slide

  14. νϟοτAPI: RESTͷ৔߹
    • leaveͱkickͷҧ͍Λ៉ྷͳRESTͰදݱ͢Δͷ͕೉͍͠
    • e.g. bodyʹԿ͔͠Βͷ৘ใΛ௥Ճ͢Δ౳ͷ޻෉͕ඞཁ
    • leave:
    • PATCH https://example.com/api/channels/123/users/456
    • body: {“status”: “left”}
    • kick:
    • PATCH https://example.com/api/channels/123/users/456
    • body: {“status”: “kicked”}
    https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/

    View full-size slide

  15. νϟοτAPI: RESTͷ৔߹
    • ҎԼͷΑ͏ʹ͢ΔͱRESTͱRPCͷதؒͷΑ͏ͳ΋ͷʹͳͬͯ͠·͏
    • leave:
    • POST https://example.com/api/channels/123/users/456/leave
    • kick:
    • POST https://example.com/api/channels/123/users/456/kick
    https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/

    View full-size slide

  16. νϟοτAPI: RPCͷ৔߹
    • leave:
    • https://example.com/api/leaveFromChannel
    • body: {“channel_id”: 123, “user_id”: 456}
    • kick:
    • https://example.com/api/kickFromChannel
    • body: {“channel_id”: 123, “user_id”: 456}
    https://www.smashingmagazine.com/2016/09/understanding-rest-and-rpc-for-http-apis/

    View full-size slide

  17. Slackͷweb API͸RPC
    > The Web API is a collection of HTTP RPC-style
    methods, all with URLs in the form
    `https://slack.com/api/METHOD_FAMILY.method`.
    https://api.slack.com/web
    Web API͸HTTP RPCελΠϧͷϝιουͷू·ΓͰ͋ΓɺશͯҎ
    ԼͷϑΥʔϜͰද͞Ε·͢ɻ
    `https://slack.com/api/METHOD_FAMILY.method`.

    View full-size slide

  18. ͦͷଞͷAPI
    • Dropbox API v2ͷେ൒͸RPC
    • AWS APIͷҰ෦͸RPC
    • Discord API͸REST
    https://www.dropbox.com/developers/documentation/http/documentation
    https://docs.aws.amazon.com/Route53/latest/APIReference/requests-rpc.html
    https://github.com/discordapp/discord-api-docs/blob/master/docs/Reference.md

    View full-size slide

  19. ͜ͷ߲ͷ·ͱΊ
    • RESTͱRPC͸దࡐదॴ
    • ϦιʔεΛத৺ʹߟ͑Δͱྑ͍ͳΒREST
    • ΞΫγϣϯΛத৺ʹߟ͑Δͱྑ͍ͳΒRPC

    View full-size slide

  20. ͦͷଞͷREST, RPCͷൺֱݕ౼ʹ
    ؔ͢Δࢀߟ
    • https://speakerdeck.com/petitviolet/web-api-
    design
    • https://www.slideshare.net/disc99_/apirestgrpc
    • https://apihandyman.io/do-you-really-know-why-
    you-prefer-rest-over-rpc/
    • https://philsturgeon.uk/api/2017/12/18/rest-
    confusion-explained/

    View full-size slide

  21. gRPC
    • Google͕։ൃΛ࢝ΊͨΦʔϓϯιʔεͷRPCϑϨʔϜϫʔΫ
    • ݩ͸Googleࣾ಺ͷϚΠΫϩαʔϏεΛͭͳ͛ΔͨΊʹ10
    ೥Ҏ্࢖ΘΕ͍ͯͨRPCϑϨʔϜϫʔΫ”Stubby”
    • HTTP/2
    • ૒ํ޲ετϦʔϛϯά
    • ެࣜʹ͸Android JavaؚΊ10ݴޠʹରԠ
    https://grpc.io/blog/principles

    View full-size slide

  22. gRPCͷσʔλදݱܗࣜ
    • σϑΥϧτͰ͸Protocol Buffers (Protobuf)
    • C++ͱGoͰ͸FlatBuffers΋αϙʔτ͞Εͯ
    ͍Δͱͷ͜ͱ
    • ଞͷϑΥʔϚοτ΋ٕज़తʹ͸ରԠՄೳͱ
    ॻ͍ͯ͋Δ͕ɺݱ࣌఺ͰରԠࡁΈ͔͸ผ
    https://grpc.io/blog/flatbuffers
    https://grpc.io/faq/

    View full-size slide

  23. grpc-gateway:
    gRPC/ProtobufͱREST/JSONΛม׵
    https://github.com/grpc-ecosystem/grpc-gateway

    View full-size slide

  24. ͍ͪAndroid։ൃऀ͔Βݟͨ
    gRPCͷϝϦοτ
    • ௨৴ʹඞཁͳίʔυ͕ࣗಈੜ੒͞ΕΔ
    • RPCϑϨʔϜϫʔΫͱͯ͠ແ೉ͳબ୒
    • Google͕࣮ࡍʹ࢖͍ͬͯΔͱ͍͏҆৺ײ
    • ૒ํ޲ετϦʔϛϯά͕ඞཁͳαʔϏεͰಛ
    ʹ໾ཱͭ͸ͣ

    View full-size slide

  25. ͍ͪAndroid։ൃऀ͔Βݟͨ
    gRPCͷσϝϦοτ
    • ੈͷதͷ৘ใ͕·ͩे෼Ͱ͸ͳ͍
    • e.g. TLS 1.2͕ຊ౰ʹͪΌΜͱ࢖ΘΕ͍ͯΔͷ͔Λௐ΂ΔͨΊʹ
    grpc-javaͷιʔείʔυΛಡΜͩΓ
    • https://github.com/grpc/grpc-java/blob/master/
    SECURITY.md ͳͲެࣜͷࢿྉ͸͋Γ·͢
    • e.g. AndroidΫϥΠΞϯτ͸Java, GoͰॻ͔Εͨαʔόͱ͸௨৴Ͱ
    ͖ΔͷʹNode.js, RubyͰॻ͔Εͨαʔόͱ͸௨৴Ͱ͖ͳ͍ࣄ৅ʹ
    ૺ۰ͨ͠Γʢ2017೥ͷ࿩ʣ

    View full-size slide

  26. Twitchͷݴ͏gRPCͷσϝϦοτ
    • ಺෦࣮૷ͷෳࡶ͞ʹىҼ͢Δ໰୊
    • HTTP/1.1Λ࢖͑ͳ͍͜ͱʹΑΔޓ׵ੑͷ໰୊
    • ProtobufͷΤϯίʔυܗ͕ࣜόΠφϦͰѻ͍
    ͮΒ͍
    • etc
    https://blog.twitch.tv/twirp-a-sweet-new-rpc-framework-for-go-5f2febbf35f

    View full-size slide

  27. gRPCͷର߅അ”Twirp”
    • 2018೥1݄ެ։ͷTwitch੡RPCϑϨʔϜϫʔΫ
    • γϯϓϧ͔ͭHTTP/1.1Λ࢖͑ΔʢHTTP/2΋Մʣ
    • ࣮૷ʹProtobufΛ࢖͏͕ɺbodyͷΤϯίʔυܗࣜ͸ProtobufʢόΠφϦʣ͚ͩͰͳ͘
    JSON΋Մ
    • ࣮͸Protobufࣗମ͕JSON΁ΤϯίʔσΟϯάͰ͖ΔʢJSON Mappingʣ
    • gRPCͰ͸ඇαϙʔτͷ໛༷
    • ૒ํ޲ετϦʔϛϯά͸ඇαϙʔτ
    • Twitch੡͸GoɺαʔυύʔςΟ੡͸Java, Lua, JS, RubyͳͲ
    https://blog.twitch.tv/twirp-a-sweet-new-rpc-framework-for-go-5f2febbf35f
    https://groups.google.com/forum/#!topic/grpc-io/ncVgOlp16F8

    View full-size slide

  28. Android JavaͰͷgRPCͷ࢖͍ํ
    • ProtobufͱҰॹʹ࢖͏ͨΊɺઌʹProtobufʹ
    ͍ͭͯઆ໌͠·͢

    View full-size slide

  29. ͜ͷ߲ͷ·ͱΊ
    • gRPC͸GoogleൃͷRPCϑϨʔϜϫʔΫ
    • HTTP/2, ૒ํ޲ετϦʔϛϯάͳͲ
    • σϑΥϧτͰ͸ProtobufͱҰॹʹ࢖͏
    • ௨৴ʹඞཁͳίʔυΛࣗಈੜ੒

    View full-size slide

  30. Protocol Buffers?

    View full-size slide

  31. Protocol Buffers (Protobuf)
    • XML౳ͷΑ͏ʹߏ଄Խ͞Εͨσʔλදݱܗࣜɺ
    ͳ͍͠͸IDL (Interface Description Language)
    • ݱࡏͷ࠷৽͸ver.3 (proto3)
    > think XML, but smaller, faster, and simpler.
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  32. .protoϑΝΠϧ
    syntax = "proto3";
    message Bank {
    int32 code = 1;
    string name = 2;
    string name_kana = 3;
    }
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  33. Protobufͱ͸
    • .protoϑΝΠϧΛαʔόɾΫϥΠΞϯτؒͰڞ༗
    • Protobuf compilerʹΑͬͯ.protoϑΝΠϧ͔ΒγϦΞϥΠζɾσγϦΞϥΠ
    ζ༻ͷΫϥε͕ੜ੒͞ΕΔ
    • όΠφϦʹΤϯίʔυͯ͠ૹ৴
    • JSON΁Τϯίʔυ͢Δ͜ͱ΋Մ
    • ͨͩ͠ઌड़ͷ௨ΓgRPCͰ͸ະαϙʔτɺTwirpͰ͸αϙʔτ͍ͯ͠Δ໛༷
    • ެࣜɾαʔυύʔςΟ߹Θͤͯ10छྨҎ্ͷݴޠʹରԠ
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  34. γϦΞϥΠζ (Java)
    Bank bank = Bank.newBuilder()
    .setCode(123)
    .setName("υϩΠυۜߦ")
    .setNameKana("υϩΠυΪϯί΢")
    .build();
    output = new FileOutputStream(path);
    bank.writeTo(output);
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  35. σγϦΞϥΠζ (C++)
    Bank bank;
    fstream input(path, ios::in | ios::binary);
    bank.ParseFromIstream(&input);
    int code = bank.code();
    string name = bank.name();
    string nameKana = bank.nameKana();
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  36. େ·͔ͳ։ൃͷྲྀΕ
    1.protoϑΝΠϧΛॻ͘
    2.αʔόɾΫϥΠΞϯτؒͰ.protoϑΝΠϧΛڞ༗͢Δ
    3.֤ݴޠ༻ͷίϯύΠϥͰ.protoΛίϯύΠϧ͢Δ
    • Androidͷ৔߹ɺbuild࣌ʹࣗಈతʹίϯύΠϧ͕
    ࣮ߦ͞ΕΔΑ͏.gradleΛॻ͍͓ͯ͘
    4.ੜ੒͞ΕͨΫϥεΛ֤ίʔυͰ࢖͏

    View full-size slide

  37. ഑ྻͱmessageͷೖΕࢠ
    message GetBanksResponse {
    repeated Bank bank = 1;
    }
    message Bank {
    int32 code = 1;
    string name = 2;
    string name_kana = 3;
    }
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  38. Enum
    enum BankAccountType {
    SAVING = 0; // ී௨
    CHECKING = 1; // ౰࠲
    }
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  39. Enum
    enum BankAccountType {
    option allow_alias = true;
    SAVING = 0; // ී௨
    CHECKING = 1; // ౰࠲
    CURRENT = 1; // ౰࠲ʢผ໊ʣ
    }
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  40. @Deprecated
    message Bank {
    int32 code = 1;
    string name = 2;
    string name_kana = 3 [deprecated=true];
    string name_katakana = 4;
    }
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  41. RPC
    service BankListService {
    rpc GetBanks (GetBanksRequest) returns (GetBanksResponse);
    }
    message GetBanksRequest {}
    message GetBanksResponse {
    repeated Bank bank = 1;
    }
    https://developers.google.com/protocol-buffers/docs/overview

    View full-size slide

  42. ͍ͪAndroid։ൃऀ͔Βݟͨ
    ProtobufͷϝϦοτ
    • ܕ͕͋Δɹ
    • messageʹ૬౰͢ΔΫϥε͕ࣗಈੜ੒͞ΕΔͷͰࣗ෼Ͱॻ͘ඞཁ͕ͳ͍
    • αʔόαΠυͷ։ൃऀͱίϛϡχέʔγϣϯ͠΍͍͢
    • protoϑΝΠϧ͕ͦͷ··࢓༷ʹͳΔ
    • protoϑΝΠϧ͕؆қͳͷͰཉ͍͠Ϋϥε΍API͕͋ͬͨΒprotoϑΝ
    ΠϧΛॻ͍ͯPRΛૹΕ͹ྑ͍
    • ΋ͪΖΜαʔόαΠυͷ࣮૷͕ඞཁʹͳΔ

    View full-size slide

  43. ͍ͪAndroid։ൃऀ͔Βݟͨ
    ProtobufͷσϝϦοτ
    • όΠφϦͰ௨৴͞ΕΔͷͰhuman readableͰ͸ͳ͍
    • ※ JSON Mappingػೳ͸͋Δ͕ɺgRPCͰ͸ඇαϙʔτͷ໛༷
    • curl΍charlesͳͲͰσόοάͰ͖ͳ͍ɺϒϥ΢βͰΞΫηεͯ͠Ϩεϙϯ
    εΛݟΔ͜ͱ͕Ͱ͖ͳ͍
    • ͪΌΜͱ௨৴Ͱ͖͍ͯΔ͔Ͳ͏͔Λ֬ೝ͢ΔͨΊʹ؆୯ͳΫϥΠΞϯτΛ
    ॻ͍͓ͯ͘ඞཁ͕͋Δ
    • αʔόɾΫϥΠΞϯτؒͷprotoϑΝΠϧΛྑ͍ײ͡ʹಉظ͢Δ࢓૊Έ͕ඞཁ
    • ҰྫΛޙड़͠·͢

    View full-size slide

  44. ͜ͷ߲ͷ·ͱΊ
    • Protocol Buffers͸ߏ଄Խ͞Εͨσʔλදݱܗࣜͳ͍͠͸
    IDL (Interface Description Language)
    • protoϑΝΠϧΛॻ͍ͯαʔόɾΫϥΠΞϯτؒͰڞ༗
    • Ϧονͳදݱྗ
    • ProtobufίϯύΠϥͰmessageʹ૬౰͢ΔΫϥεͷࣗ
    ಈੜ੒

    View full-size slide

  45. gRPC + Protocol BuffersΛ
    AndroidΞϓϦʹಋೖ͢Δ

    View full-size slide

  46. खॱ
    1.gRPCͱProtobufΛΠϯετʔϧ͢Δ
    2.Ϗϧυ࣌ʹProtobuf͔ΒίʔυΛࣗಈੜ੒͢ΔλεΫΛ
    ॻ͘
    3.protoϑΝΠϧΛॻ͘
    4.Ϗϧυͯ͠ίʔυੜ੒
    5.ΞϓϦ಺Ͱੜ੒͞ΕͨίʔυΛॻ͘

    View full-size slide

  47. ஫: ඞͣެࣜͷREADMEΛ֬ೝ
    • gRPC-Java:
    • https://github.com/grpc/grpc-java
    • Android޲͚ͱͦͷଞͷJava؀ڥ޲͚Ͱ಺༰͕ҟͳΔͷͰࠞಉ͠ͳ͍ཁ
    ஫ҙ
    • Protobuf:
    • https://github.com/google/protobuf-gradle-plugin
    • αϯϓϧ:
    • https://github.com/grpc/grpc-java/tree/master/examples/android

    View full-size slide

  48. // build.gradle
    buildscript {
    ...
    dependencies {
    ...
    classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.3'
    }
    }
    // app/build.gradle
    apply plugin: ‘com.android.application’
    apply plugin: 'com.google.protobuf'
    dependencies {
    ...
    compile 'io.grpc:grpc-okhttp:1.9.0'
    compile 'io.grpc:grpc-protobuf-lite:1.9.0'
    compile 'io.grpc:grpc-stub:1.9.0'
    }

    View full-size slide

  49. // app/build.gradle
    protobuf {
    protoc {
    artifact = ‘com.google.protobuf:protoc:3.5.1-1’
    }
    plugins {
    javalite {
    artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0"
    }
    grpc {
    artifact = “io.grpc:protoc-gen-grpc-java:1.9.0”
    }
    }
    generateProtoTasks {
    all().each { task ->
    task.plugins {
    javalite {}
    grpc {
    option 'lite'
    }
    }
    }
    }
    }

    View full-size slide

  50. 3. protoϑΝΠϧΛॻ͘
    • src/main/proto ΍ src/test/proto ҎԼʹproto
    ϑΝΠϧΛஔ͘
    • ҎԼͷίϚϯυͰprotoϑΝΠϧ͕ίϯύΠ
    ϧՄೳ͔֬ೝͰ͖Δ
    • $ protoc —java_out= foo.proto

    View full-size slide

  51. 4. Ϗϧυͯ͠ίʔυੜ੒
    • ASͰϏϧυΛ࣮ߦ͢ΔͱҎԼʹprotoϑΝΠϧ
    ͔Βੜ੒͞ΕͨJavaίʔυ͕ஔ͔ΕΔ
    • app/build/generated/source/proto/

    View full-size slide

  52. service BankListService {
    rpc GetBanks (GetBanksRequest) returns (GetBanksResponse);
    }
    message GetBanksRequest {}
    message GetBanksResponse {
    repeated Bank bank = 1;
    }

    View full-size slide

  53. ManagedChannel channel = OkHttpChannelBuilder
    .forAddress("example.com", "443")
    .build();
    BankListServiceStub stub = BankListServiceGrpc.newStub(channel);
    GetBanksRquest request = GetBanksRequest
    .newBuilder()
    .build();
    stub.getBanks(request, new StreamObserver() {
    @Override
    public void onNext(GetBanksResponse response) {
    List banks = response.getBankList()
    ...
    }
    @Override
    public void onError(Throwable throwable) {
    ...
    }
    @Override
    public void onCompleted() {
    ...
    }
    );

    View full-size slide

  54. ͜ͷ߲ͷ·ͱΊ
    • AndroidͰ͸gRPC-JavaͱProtocol Buffers
    Gradle Plugin͕ඞཁ
    • gRPC + Protocol Buffersͷಋೖ࣌͸ඞͣެࣜ
    ϦϙδτϦͷREADMEΛ֬ೝʂʂ

    View full-size slide

  55. ։ൃ্ͷ޻෉

    View full-size slide

  56. ֤repoͷprotoϑΝΠϧͷಉظ
    proto files repo
    iOS app repo Android app repo API server repo
    proto files proto files proto files
    ྑ͍ײ͡ʹprofo files repoΛίϐʔ or ࢀর͍ͨ͠

    View full-size slide

  57. proto files repo
    Digdag
    GCP Cloud Functions
    iOS app repo
    Android app repo
    API server repo
    1. PRϚʔδͰwebhookૹ৴
    2. DigdagϫʔΫϑϩʔIDΛ
    ɹࢦఆͯ͠ϫʔΫϑϩʔىಈ
    3. ֤repoͷprofo filesΛ
    ɹߋ৽͢ΔPRΛ࡞੒
    4. PRͷࠩ෼ΛݟͯϚʔδʢखಈʣ

    View full-size slide

  58. proto files repo
    Digdag
    GCP Cloud Functions
    iOS app repo
    Android app repo
    API server repo
    1. PRϚʔδͰwebhookૹ৴
    2. DigdagϫʔΫϑϩʔIDΛ
    ɹࢦఆͯ͠ϫʔΫϑϩʔىಈ
    3. ֤repoͷprofo filesΛ
    ɹߋ৽͢ΔPRΛ࡞੒
    4. PRͷࠩ෼ΛݟͯϚʔδʢखಈʣ

    View full-size slide

  59. GitHubͷwebhookઃఆը໘

    View full-size slide

  60. proto files repo
    Digdag
    GCP Cloud Functions
    iOS app repo
    Android app repo
    API server repo
    1. PRϚʔδͰwebhookૹ৴
    2. DigdagϫʔΫϑϩʔIDΛ
    ɹࢦఆͯ͠ϫʔΫϑϩʔىಈ
    3. ֤repoͷprofo filesΛ
    ɹߋ৽͢ΔPRΛ࡞੒
    4. PRͷࠩ෼ΛݟͯϚʔδʢखಈʣ

    View full-size slide

  61. exports.syncTheoProto = function syncTheoProto (req, res) {
    ...
    postData = {
    "workflowId": settings.workflowId,
    ...
    }
    req.write(JSON.stringify(postData));
    req.end();
    ...
    };
    POSTϦΫΤετʹ༧Ί࡞͓͍ͬͯͨ
    DigdagϫʔΫϑϩʔͷIDΛ෇Ճ͢Δ

    View full-size slide

  62. proto files repo
    Digdag
    GCP Cloud Functions
    iOS app repo
    Android app repo
    API server repo
    1. PRϚʔδͰwebhookૹ৴
    2. DigdagϫʔΫϑϩʔIDΛ
    ɹࢦఆͯ͠ϫʔΫϑϩʔىಈ
    3. ֤repoͷprofo filesΛ
    ɹߋ৽͢ΔPRΛ࡞੒
    4. PRͷࠩ෼ΛݟͯϚʔδʢखಈʣ

    View full-size slide

  63. proto files repo
    Digdag
    GCP Cloud Functions
    iOS app repo
    Android app repo
    API server repo
    1. PRϚʔδͰwebhookૹ৴
    2. DigdagϫʔΫϑϩʔIDΛ
    ɹࢦఆͯ͠ϫʔΫϑϩʔىಈ
    3. ֤repoͷprofo filesΛ
    ɹߋ৽͢ΔPRΛ࡞੒
    4. PRͷࠩ෼ΛݟͯϚʔδʢखಈʣ

    View full-size slide

  64. ͜ͷ߲ͷ·ͱΊ
    • protoϑΝΠϧΛαʔόɾΫϥΠΞϯτؒͰಉ
    ظ͢Δ࢓૊Έ͕͋Δͱศར
    • ࠓͷͱ͜Ζwebhook, αʔόʔϨεΞϓϦ
    έʔγϣϯ, ϫʔΫϑϩʔΤϯδϯΛ૊Έ߹
    Θͤͯӡ༻͍ͯ͠·͢

    View full-size slide

  65. ࠷ޙʹ…
    Swagger or GraphQL or gRPC???
    • গͳ͘ͱ΋ݱ࣌఺ͰͲΕ͔͕ઈରతʹྑ͍ͱ͍͏͜ͱ͸ແͦ͞͏
    • ൺֱهࣄ͕୔ࢁ͋Δ
    • e.g. https://brandur.org/api-paradigms
    • ͜ͷهࣄʹର͢Δٞ࿦: https://news.ycombinator.com/item?id=14003134
    • DroidKaigi 2018Ͱ΋ൃද͞Εͨʂ
    • Swagger: https://speakerdeck.com/magiepooh/madaapiding-yi-guan-li-
    dexiao-hao-siterufalse-swaggerwoyong-itada-gui-mo-apurishi-dai-falseapiding-
    yi-guan-li-tokodozienereto
    • GraphQL: https://speakerdeck.com/gfx/subarasikigraphqlfalsesekaiheyoukoso

    View full-size slide

  66. ൃදͷ·ͱΊ
    • RESTͱRPC͸దࡐదॴ
    • gRPC͸GoogleൃͷRPCϑϨʔϜϫʔΫ
    • Protobuf͸ߏ଄Խ͞Εͨσʔλදݱܗࣜͳ͍͠͸IDL
    • gRPC + ProtobufͰίʔυΛࣗಈੜ੒
    • ಋೖ࣌͸ඞͣ࠷৽ͷެࣜREADMEΛ֬ೝ
    • ProtobufΛαʔόɾΫϥΠΞϯτؒͰಉظ͢Δ࢓૊ΈΛ࡞Ζ͏
    • Swagger΍GraphQLʹ͍ͭͯ΋ௐ΂ͯΈΑ͏

    View full-size slide