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

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

Nao Minami

June 29, 2019
Tweet

More Decks by Nao Minami

Other Decks in Technology

Transcript

  1. ©2019 Wantedly, Inc.
    HDQD
    (PPHMF$MPVE1VC4VC$MJFOU
    GPS3VCZ
    29.Jun.2019 - Nao Minami (@south37) Wantedly, Inc.
    TokyuRubyձٞ13

    View full-size slide

  2. ©2018 Wantedly, Inc.
    /BP.JOBNJ
    *OGSBTUSVDUVSF&OHJOFFS 8BOUFEMZ *OD
    (JU)VCTPVUI
    5XJUUFSTPVUI
    43&ͱͯ͠ͷ໾ׂʢαʔϏεͷ৴པੑʹ੹೚ʣ
    ։ൃج൫ͱͯ͠ͷ໾ׂʢΤϯδχΞͷੜ࢈ੑʹ੹೚ʣ

    View full-size slide

  3. ©2018 Wantedly, Inc.
    ಥવͰ͕͢ɺ
    (PPHMF$MPVE1VC4VC
    ʹ͍ͭͯܰ͘঺հ͍ͤͯͩ͘͞͞ʂ

    View full-size slide

  4. ©2018 Wantedly, Inc.
    (PPHMF$MPVE1VC4VCͱ͸
    ($1͕ఏڙ͢Δ.BOBHFE
    1VC4VC.FTTBHF2VFVF4FSWJDF
    w UPQJDʹNFTTBHFΛQVCMJTI
    w UPQJD͔Βෳ਺ͷTVCTDSJQUJPOʹNFTTBHFΛ഑৴
    w TVCTDSJQUJPO͝ͱʹNFTTBHF͕ॲཧ͞ΕΔ
    IUUQTDMPVEHPPHMFDPNQVCTVCEPDTPWFSWJFXΑΓҾ༻

    View full-size slide

  5. ©2018 Wantedly, Inc.
    ͳͥ(PPHMF$MPVE1VC4VCΛར༻͢Δͷ͔
    .FTTBHF2VFVFͱͯ͠ͷϢʔεέʔεར఺
    w DPOTVNFSͷෛՙͷόϥϯεௐ੔ʢ4QJLFΛӅ͢ $POTVNFSͷ4DBMFPVUʣ
    w ඇಉظϫʔΫϩʔυͷ࣮૷ʢ1VCMJTIFS͸$POTVNFSͷॲཧΛ଴ͨͳ͍ʣ
    w ৴པੑͷ޲্ʢ$POTVNFSʹো֐͕ى͖ͯ΋1VCMJTIFS͸ॲཧΛܧଓՄೳʣ
    IUUQTBOXBBSMBCTXPSEQSFTTDPNNFTTBHFRVFVFQBSUKNTEPNBJOTΑΓҾ༻

    View full-size slide

  6. ©2018 Wantedly, Inc.
    ͳͥ(PPHMF$MPVE1VC4VCΛར༻͢Δͷ͔
    1VC4VCͱͯ͠ͷϢʔεέʔεར఺
    w ಉ͡NFTTBHFΛɺ4VCTDSJCFS͝ͱʹࣗ෼ͷϖʔεͰॲཧͰ͖Δ
    w 1VCMJTIFSʹखΛೖΕͣʹɺ4VCTDSJCFSΛ૿΍͢͜ͱ͕Ͱ͖Δʢؔ৺ࣄΛ෼཭ʣ
    w Ϣʔεέʔε
    w ෼ࢄΩϟογϡͷߋ৽
    w Πϕϯτ௨஌ͷ഑৴
    w ෳ਺ͷγεςϜ΁ͷMPHHJOH
    w FUD
    IUUQTNTRVBSFDPNBVXIZNFTTBHJOHRVFVFTNJHIUOPUTVDLΑΓҾ༻

    View full-size slide

  7. ©2018 Wantedly, Inc.
    (PPHMF$MPVE1VC4VC
    ͸ͱͯ΋ศརʂ

    View full-size slide

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

    View full-size slide

  9. ©2018 Wantedly, Inc.

    View full-size slide

  10. ©2018 Wantedly, Inc.

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  13. ©2018 Wantedly, Inc.
    HPPHMFDMPVEQVCTVCHFNʹ଍Γͳ͍෦෼
    1MVHJOػߏ͕ͳ͍
    w 1VCMJTIFS4VCTDSJCFSʹ͸ɺNFTTBHFͷॏෳഉআͳͲʮڞ௨ͰඞཁʹͳΔػೳʯ͕සग़͢Δ
    w ʮ൚༻తͳػೳ͸1MVHJOͰఏڙ͞ΕΔʯͱ͍͏ମݧ͕ཉ͍͠
    1SPDFTTͷϥΠϑαΠΫϧ͸ࣗ෼Ͱ؅ཧ͢Δඞཁ
    ͋Γ
    w ʮ4*(5&3.Λड͚औͬͨΒHSBDFGVMTIVUEPXOʯͳͲ͸ࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δ

    View full-size slide

  14. ©2018 Wantedly, Inc.
    ͦ͜ͰɺHDQDʂʂʂ

    View full-size slide

  15. ©2018 Wantedly, Inc.

    View full-size slide

  16. ©2018 Wantedly, Inc.

    View full-size slide

  17. ©2018 Wantedly, Inc.
    HDQDͷఏڙ͢Δػೳ
    1MVHJOػߏΛαϙʔτ
    w JOUFSDFQUPSͱ͍͏ܗͰ࣮૷ͨ͠QMVHJOΛར༻Մೳ
    w සग़ͷJOUFSDFQUPS͸IUUQTHJUIVCDPNTPVUIHDQDJOUFSDFQUPSTͱ͍͏HFNͰެ։
    σϑΥϧτͰ4*(5&3.Ͱ(SBDFGVMTIVUEPXO
    w SVOϝιουʹ౉͢ΦϓγϣϯͰɺͲͷTJHOBMͰ(SBDFGVMTIVUEPXO͢Δ͔Λ੍ޚ͢Δ͜ͱ
    ΋Մೳ

    View full-size slide

  18. ©2018 Wantedly, Inc.
    HDQDͷ࢖͍ํ1VCMJTIFS
    publisher = Gcpc::Publisher.new(
    project_id: "”,
    topic: "”,
    credentials: “/path/to/credentials",
    )
    publisher.publish("")
    (DQD1VCMJTIFSͰQVCMJTI
    w DSFEFOUJBMΛ౉ͯ͠JOJUJBMJ[FɺQVCMJTINFUIPEͰQVCMJTI

    View full-size slide

  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࣌ͷػೳΛ௥Ճ

    View full-size slide

  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Λొ࿥

    View full-size slide

  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࣌ͷػೳΛ௥Ճ

    View full-size slide

  22. ©2018 Wantedly, Inc.
    ͥͻɺ࢖ͬͯΈͯϑΟʔυόοΫΛ
    ΋Β͑Δͱخ͍͠Ͱ͢ʂ

    View full-size slide

  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ͱͯ͠ఏڙ

    View full-size slide

  24. ©2019 Wantedly, Inc.
    w )BM(BUFXPPEIUUQTVOTQMBTIDPNQIPUPT/[C-#TDUZ2
    1IPUP$SFEJU

    View full-size slide