gcpc: Google Cloud Pub/Sub Client for Ruby #tqrk13

gcpc: Google Cloud Pub/Sub Client for Ruby #tqrk13

TokyuRuby会議13 で、gcpc という Google Cloud Pub/Sub を便利に利用する為の gem について話しました!
#tqrk13 #プレモルセミナー
https://github.com/south37/gcpc
https://github.com/south37/gcpc-interceptors

2b4f9f20b554d4c77c46fe6a9930d6fe?s=128

Nao Minami

June 29, 2019
Tweet

Transcript

  1. ©2019 Wantedly, Inc. HDQD (PPHMF$MPVE1VC4VC$MJFOU GPS3VCZ 29.Jun.2019 - Nao Minami

    (@south37) Wantedly, Inc. TokyuRubyձٞ13
  2. ©2018 Wantedly, Inc. /BP.JOBNJ *OGSBTUSVDUVSF&OHJOFFS 8BOUFEMZ *OD (JU)VCTPVUI 5XJUUFSTPVUI 

    43&ͱͯ͠ͷ໾ׂʢαʔϏεͷ৴པੑʹ੹೚ʣ  ։ൃج൫ͱͯ͠ͷ໾ׂʢΤϯδχΞͷੜ࢈ੑʹ੹೚ʣ
  3. ©2018 Wantedly, Inc. ಥવͰ͕͢ɺ (PPHMF$MPVE1VC4VC ʹ͍ͭͯܰ͘঺հ͍ͤͯͩ͘͞͞ʂ

  4. ©2018 Wantedly, Inc. (PPHMF$MPVE1VC4VCͱ͸ ($1͕ఏڙ͢Δ.BOBHFE 1VC4VC.FTTBHF2VFVF4FSWJDF w UPQJDʹNFTTBHFΛQVCMJTI w UPQJD͔Βෳ਺ͷTVCTDSJQUJPOʹNFTTBHFΛ഑৴

    w TVCTDSJQUJPO͝ͱʹNFTTBHF͕ॲཧ͞ΕΔ IUUQTDMPVEHPPHMFDPNQVCTVCEPDTPWFSWJFXΑΓҾ༻
  5. ©2018 Wantedly, Inc. ͳͥ(PPHMF$MPVE1VC4VCΛར༻͢Δͷ͔ .FTTBHF2VFVFͱͯ͠ͷϢʔεέʔεར఺ w DPOTVNFSͷෛՙͷόϥϯεௐ੔ʢ4QJLFΛӅ͢ $POTVNFSͷ4DBMFPVUʣ w ඇಉظϫʔΫϩʔυͷ࣮૷ʢ1VCMJTIFS͸$POTVNFSͷॲཧΛ଴ͨͳ͍ʣ

    w ৴པੑͷ޲্ʢ$POTVNFSʹো֐͕ى͖ͯ΋1VCMJTIFS͸ॲཧΛܧଓՄೳʣ IUUQTBOXBBSMBCTXPSEQSFTTDPNNFTTBHFRVFVFQBSUKNTEPNBJOTΑΓҾ༻
  6. ©2018 Wantedly, Inc. ͳͥ(PPHMF$MPVE1VC4VCΛར༻͢Δͷ͔ 1VC4VCͱͯ͠ͷϢʔεέʔεར఺ w ಉ͡NFTTBHFΛɺ4VCTDSJCFS͝ͱʹࣗ෼ͷϖʔεͰॲཧͰ͖Δ w 1VCMJTIFSʹखΛೖΕͣʹɺ4VCTDSJCFSΛ૿΍͢͜ͱ͕Ͱ͖Δʢؔ৺ࣄΛ෼཭ʣ w

    Ϣʔεέʔε w ෼ࢄΩϟογϡͷߋ৽ w Πϕϯτ௨஌ͷ഑৴ w ෳ਺ͷγεςϜ΁ͷMPHHJOH w FUD IUUQTNTRVBSFDPNBVXIZNFTTBHJOHRVFVFTNJHIUOPUTVDLΑΓҾ༻
  7. ©2018 Wantedly, Inc. (PPHMF$MPVE1VC4VC ͸ͱͯ΋ศརʂ

  8. ©2018 Wantedly, Inc. Ͱ͸ɺ3VCZ͔Βར༻͍ͨ͠৔߹͸ʁ

  9. ©2018 Wantedly, Inc.

  10. ©2018 Wantedly, Inc.

  11. ©2018 Wantedly, Inc. (PPHMF͕HPPHMFDMPVEQVCTVCHFN Λఏڙͯ͘͠Ε͍ͯΔʂ

  12. ©2018 Wantedly, Inc. ͔͠͠ɺ ΑΓศརʹ࢖͏ͱ͍͏؍఺Ͱ͸ ͍͔ͭ͘଍Γͳ͍ػೳ͕ɻɻɻ

  13. ©2018 Wantedly, Inc. HPPHMFDMPVEQVCTVCHFNʹ଍Γͳ͍෦෼ 1MVHJOػߏ͕ͳ͍ w 1VCMJTIFS4VCTDSJCFSʹ͸ɺNFTTBHFͷॏෳഉআͳͲʮڞ௨ͰඞཁʹͳΔػೳʯ͕සग़͢Δ w ʮ൚༻తͳػೳ͸1MVHJOͰఏڙ͞ΕΔʯͱ͍͏ମݧ͕ཉ͍͠ 1SPDFTTͷϥΠϑαΠΫϧ͸ࣗ෼Ͱ؅ཧ͢Δඞཁ

    ͋Γ w ʮ4*(5&3.Λड͚औͬͨΒHSBDFGVMTIVUEPXOʯͳͲ͸ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ
  14. ©2018 Wantedly, Inc. ͦ͜ͰɺHDQDʂʂʂ

  15. ©2018 Wantedly, Inc.

  16. ©2018 Wantedly, Inc.

  17. ©2018 Wantedly, Inc. HDQDͷఏڙ͢Δػೳ 1MVHJOػߏΛαϙʔτ w JOUFSDFQUPSͱ͍͏ܗͰ࣮૷ͨ͠QMVHJOΛར༻Մೳ w සग़ͷJOUFSDFQUPS͸IUUQTHJUIVCDPNTPVUIHDQDJOUFSDFQUPSTͱ͍͏HFNͰެ։ σϑΥϧτͰ4*(5&3.Ͱ(SBDFGVMTIVUEPXO

    w SVOϝιουʹ౉͢ΦϓγϣϯͰɺͲͷTJHOBMͰ(SBDFGVMTIVUEPXO͢Δ͔Λ੍ޚ͢Δ͜ͱ ΋Մೳ
  18. ©2018 Wantedly, Inc. HDQDͷ࢖͍ํ1VCMJTIFS publisher = Gcpc::Publisher.new( project_id: "<project id>”,

    topic: "<topic name>”, credentials: “/path/to/credentials", ) publisher.publish("<message payload>") (DQD1VCMJTIFSͰQVCMJTI w DSFEFOUJBMΛ౉ͯ͠JOJUJBMJ[FɺQVCMJTINFUIPEͰQVCMJTI
  19. ©2018 Wantedly, Inc. HDQDͷ࢖͍ํ1VCMJTIFS class LogInterceptor < Gcpc::Publisher::BaseInterceptor def publish(data,

    attributes) MyLogger.info “publish data: \”#{data}\”" yield data, attributes end end publisher = Gcpc::Publisher.new( …, interceptors: [LogInterceptor], ) (DQD1VCMJTIFS͸JOUFSDFQUPSΛड͚औΕΔ w JOUFSDFQUPSͰQVCMJTI࣌ͷػೳΛ௥Ճ
  20. ©2018 Wantedly, Inc. HDQDͷ࢖͍ํ4VCTDSJCFS class NopHandler < Gcpc::Subscriber::BaseHandler def handle(data,

    attributes, message) # Do nothing. Consume only. end end subscriber = Gcpc::Subscriber.new( …, ) subscriber.handle(NopHandler) subscriber.run # Start subscribing (DQD4VCTDSJCFSͰTVCTDSJCF w NFTTBHFΛॲཧ͢ΔIBOEMFSΛొ࿥
  21. ©2018 Wantedly, Inc. HDQDͷ࢖͍ํ4VCTDSJCFS class LogInterceptor < Gcpc::Subscriber::BaseInterceptor def handle(data,

    attributes, message) MyLogger.info "subscribed a message: #{message}” yield data, attributes, message end end subscriber = Gcpc::Subscriber.new( …, interceptors: [LogInterceptor], ) (DQD4VCTDSJCFS΋JOUFSDFQUPSΛड͚औΕΔ w JOUFSDFQUPSͰTVCTDSJCF࣌ͷػೳΛ௥Ճ
  22. ©2018 Wantedly, Inc. ͥͻɺ࢖ͬͯΈͯϑΟʔυόοΫΛ ΋Β͑Δͱخ͍͠Ͱ͢ʂ

  23. ©2018 Wantedly, Inc. ·ͱΊ (PPHMF$MPVE1VC4VC͸ศར w .FTTBHF2VFVFͱͯ͠ඇಉظϫʔΫϩʔυΛ࣮ݱɺ৴པੑΛ޲্ w 1VC4VCͱ֤ͯ͠ίϯϙʔωϯτͷؔ৺ࣄΛ෼཭ ศརʹ(PPHMF$MPVE1VC4VCΛར༻͢ΔͨΊʹ

    HDQDͱ͍͏HFNΛ࡞ͬͨ w IUUQTHJUIVCDPNTPVUIHDQD w ެࣜHFNΛXSBQͯ͠1MVHJOػߏ (SBDFGVMTIVUEPXOΛ௥Ճ w 1MVHJOͷDPMMFDUJPOΛIUUQTHJUIVCDPNTPVUIHDQDJOUFSDFQUPSTͱͯ͠ఏڙ
  24. ©2019 Wantedly, Inc. w )BM(BUFXPPEIUUQTVOTQMBTIDPNQIPUPT/[C-#TDUZ2 1IPUP$SFEJU