Slide 1

Slide 1 text

©2018 Wantedly, Inc. Rails͔ΒProtobufΛ ࢖͍ͨ͘ͳͬͨ࿩ Cloud Pub/Sub ͰͷεΩʔϚ؅ཧ 2018.9.20 - @rerost/@hazumirr

Slide 2

Slide 2 text

©2018 Wantedly, Inc. ࣗݾ঺հ Ұᑍ୺੅!IB[VNJSS!SFSPTU 8FC"QQMJDBUJPO&OHJOFFS 3BJMT (P 3FBDUʜ ۴࿏ߴઐஜ೾େֶ8BOUFEMZ

Slide 3

Slide 3 text

©2018 Wantedly, Inc. ۴࿏ߴઐ

Slide 4

Slide 4 text

©2018 Wantedly, Inc. 8BOUFEMZ1FPQMF ೥ϦϦʔε ϚΠΫϩαʔϏεʢ(P 3VCZ ʜʣ 8BOUFEMZ7JTJU ೥ϦϦʔε ϞϊϦγοΫͳ3BJMTΞϓϦέʔγϣϯ

Slide 5

Slide 5 text

©2018 Wantedly, Inc. ืू ϑΟʔυ εΧ΢τ

Slide 6

Slide 6 text

©2018 Wantedly, Inc.

Slide 7

Slide 7 text

©2018 Wantedly, Inc. ຖ೔શͯͷεΧ΢τ༻ͷϢʔβʔσʔλΛೖΕ௚͍ͯ͠Δ ࠩ෼ͷσʔλ͚ͩཉ͍͠ WJTJUࣗମͷ։ൃͱผαΠΫϧͰճ͍ͨ͠ σʔλ෼ੳ෦෼ #JH2VFSZͳͲΛѻ͏

Slide 8

Slide 8 text

©2018 Wantedly, Inc. վળํ๏ ͪΐͬͱͣͭվળ͍ͯ͘͠ ϚΠΫϩαʔϏεʹ੾Γग़͢

Slide 9

Slide 9 text

©2018 Wantedly, Inc. εΧ΢τͷػೳ ߜΓࠐΈ ਪન Ϣʔβʔ৘ใͷදࣔ ϚΠΫϩαʔϏεʹ੾Γग़ͯ͠ ੔ཧ͍ͨ͠

Slide 10

Slide 10 text

©2018 Wantedly, Inc. εΧ΢τͷσʔλ෼ੳ͢Δਓ

Slide 11

Slide 11 text

©2018 Wantedly, Inc. ΋͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ

Slide 12

Slide 12 text

©2018 Wantedly, Inc. 7JTJUͷ੹຿͕΍͹͍

Slide 13

Slide 13 text

©2018 Wantedly, Inc. ΋͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ ௨஌ͯ͘͠ΕΔԿ͔

Slide 14

Slide 14 text

©2018 Wantedly, Inc. $MPVE1VC4VC

Slide 15

Slide 15 text

©2018 Wantedly, Inc. https://cloud.google.com/pubsub/docs/overview

Slide 16

Slide 16 text

©2018 Wantedly, Inc. ΋͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ

Slide 17

Slide 17 text

©2018 Wantedly, Inc. ϝϦοτ αʔϏε͕ؒૄ݁߹ʹͳΔ σϝϦοτ ૹΔσʔλεΩʔϚͷ؅ཧ͕೉͍͠

Slide 18

Slide 18 text

©2018 Wantedly, Inc. ΋͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ

Slide 19

Slide 19 text

©2018 Wantedly, Inc. ͦ͜Ͱ1SPUPDPM#V⒎FS γϦΞϥΠβʔɾσγϦΞϥΠβʔࣗಈੜ੒ ޓ׵ੑ͕͋Δఔ౓อͨΕΔ ੩తܕ෇͖ݴޠͰ΋͏·͘ѻ͑Δ ࣾ಺ͷଞͷνʔϜ͕࢖͍ͬͯͯ஌ݟ͕͋Δ

Slide 20

Slide 20 text

©2018 Wantedly, Inc. ΋͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ 1SPUPCVG 1SPUPCVG

Slide 21

Slide 21 text

©2018 Wantedly, Inc. Protocol Buffer

Slide 22

Slide 22 text

©2018 Wantedly, Inc. syntax = "proto3"; option ruby_package = "Protos::SamplePB"; message User { // ֶྺ message Education { string school_name = 1; } // ৬ྺ message Experience { string company_name = 1; } string user_name = 1; string introduction = 2; int64 age = 3; repeated Education educations = 4; repeated Experience experiences = 5; } TBNQMFQSPUP

Slide 23

Slide 23 text

©2018 Wantedly, Inc. # Generated by the protocol buffer compiler. DO NOT EDIT! # source: protos/sample.proto require 'google/protobuf' Google::Protobuf::DescriptorPool.generated_pool.build do add_message "User" do optional :user_name, :string, 1 optional :introduction, :string, 2 optional :age, :int64, 3 repeated :educations, :message, 4, "User.Education" repeated :experiences, :message, 5, "User.Experience" end add_message "User.Education" do optional :school_name, :string, 1 end add_message "User.Experience" do optional :company_name, :string, 1 end end module Protos::SamplePB User = Google::Protobuf::DescriptorPool.generated_pool.lookup("User").msgclass User::Education = Google::Protobuf::DescriptorPool.generated_pool.lookup("User.Education").msgclass User::Experience = Google::Protobuf::DescriptorPool.generated_pool.lookup("User.Experience").msgclass end TBNQMFQCSC

Slide 24

Slide 24 text

©2018 Wantedly, Inc. def new_sample educations = [ Protos::SamplePB::User::Education.new( school_name: "۴࿏ߴઐ" ), Protos::SamplePB::User::Education.new( school_name: "ஜ೾େֶ" ), ] experiences = [ Protos::SamplePB::User::Experience.new( company_name: "΢ΥϯςουϦʔגࣜձࣾ" ), ] Protos::SamplePB::User.new( user_name: 'rerost', introduction: 'δϟεί͔Β110km', educations: educations, experiences: experiences, ) end sample = new_sample puts Protos::SamplePB::User.encode_json(sample) { "userName": "rerost", "introduction": "δϟεί͔Β110km", "educations": [ { "schoolName": "۴࿏ߴઐ" }, { "schoolName": "ஜ೾େֶ" } ], "experiences": [ { "companyName": "΢ΥϯςουϦʔגࣜձࣾ" } ] }

Slide 25

Slide 25 text

©2018 Wantedly, Inc. def new_sample Protos::SamplePB::User.new( user_name: 1, # Τϥʔ user_nameͷܕ͕ҧ͏ͷͰ age: 23, introduction: 'δϟεί͔Β110km', educations: [], experiences: [], ) end sample = new_sample ҧ͏ܕΛೖΕͨ৔߹ʹ͍ͭͯ

Slide 26

Slide 26 text

©2018 Wantedly, Inc. def new_sample Protos::SamplePB::User.new() end sample = new_sample puts sample.age # 0 ஋ΛೖΕͳ͔ͬͨ৔߹ʹ͍ͭͯ

Slide 27

Slide 27 text

©2018 Wantedly, Inc. def new_sample Protos::SamplePB::User.new( age: 23, ) end sample = new_sample encoded = Protos::SamplePB::User.encode(sample) puts encoded.class # String decoded = Protos::SamplePB::User.decode(encoded) puts decoded.age # 23 CJOBSZ΁ͷγϦΞϥΠζσγϦΞϥΠζ

Slide 28

Slide 28 text

©2018 Wantedly, Inc. def new_sample Protos::SamplePB::User.new( age: 23, ) end sample = new_sample encoded = Protos::SamplePB::User.encode_json(sample) puts encoded.class # String puts encoded # {"age":23,"educations":[],"experiences":[]} decoded = Protos::SamplePB::User.decode_json(encoded) puts decoded.age # 23 +40/΁ͷγϦΞϥΠζσγϦΞϥΠζ

Slide 29

Slide 29 text

©2018 Wantedly, Inc. https://github.com/rerost/sample-protobuf

Slide 30

Slide 30 text

©2018 Wantedly, Inc. ޓ׵ੑʹ͍ͭͯ ࠷௿ݶཉ͍͠ޓ׵ੑɹ ΧϥϜͷ௥Ճ ໊લͷมߋ

Slide 31

Slide 31 text

©2018 Wantedly, Inc. ޓ׵ੑʹ͍ͭͯ ࠷௿ݶཉ͍͠ޓ׵ੑɹ ΧϥϜͷ௥Ճ ໊લͷมߋ 1SPUPCVGͳΒɾɾɾ σγϦΞϥΠζෆՄͳΧϥϜ͸ແࢹ λάφϯόʔͰࣝผ όΠφϦͳΒ

Slide 32

Slide 32 text

©2018 Wantedly, Inc. <࠶ܝ>΋͠ϚΠΫϩαʔϏεԽ͕ਐΜͩΒ 1SPUPCVG 1SPUPCVG

Slide 33

Slide 33 text

©2018 Wantedly, Inc. 1SPUPCVGΛ࢖͏͜ͱͰղܾͰ͖ͨ໰୊ɹ σʔλΛ҆ఆͯ͠΍ΓऔΓͰ͖Δ ੩తܕ෇͖ݴޠͱ΋͏·͘΍ΓͱΓ͕Ͱ͖Δ γϦΞϥΠβʔσγϦΞϥΠβʔ͕ࣗಈੜ੒Ͱ͖Δ

Slide 34

Slide 34 text

©2018 Wantedly, Inc. 1SPUPCVGPO1VC4VCͰγϯϓϧʹ ଞͷαʔϏεͱͷίϛϡχέʔγϣϯָ͕ʹ ੹຿͕ඞཁ࠷খݶʹ