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. ©2018 Wantedly, Inc. /BP.JOBNJ *OGSBTUSVDUVSF&OHJOFFS 8BOUFEMZ *OD (JU)VCTPVUI 5XJUUFSTPVUI 

    43&ͱͯ͠ͷ໾ׂʢαʔϏεͷ৴པੑʹ੹೚ʣ  ։ൃج൫ͱͯ͠ͷ໾ׂʢΤϯδχΞͷੜ࢈ੑʹ੹೚ʣ
  2. ©2018 Wantedly, Inc. ͳͥ(PPHMF$MPVE1VC4VCΛར༻͢Δͷ͔ 1VC4VCͱͯ͠ͷϢʔεέʔεར఺ w ಉ͡NFTTBHFΛɺ4VCTDSJCFS͝ͱʹࣗ෼ͷϖʔεͰॲཧͰ͖Δ w 1VCMJTIFSʹखΛೖΕͣʹɺ4VCTDSJCFSΛ૿΍͢͜ͱ͕Ͱ͖Δʢؔ৺ࣄΛ෼཭ʣ w

    Ϣʔεέʔε w ෼ࢄΩϟογϡͷߋ৽ w Πϕϯτ௨஌ͷ഑৴ w ෳ਺ͷγεςϜ΁ͷMPHHJOH w FUD IUUQTNTRVBSFDPNBVXIZNFTTBHJOHRVFVFTNJHIUOPUTVDLΑΓҾ༻
  3. ©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
  4. ©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࣌ͷػೳΛ௥Ճ
  5. ©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Λొ࿥
  6. ©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࣌ͷػೳΛ௥Ճ
  7. ©2018 Wantedly, Inc. ·ͱΊ (PPHMF$MPVE1VC4VC͸ศར w .FTTBHF2VFVFͱͯ͠ඇಉظϫʔΫϩʔυΛ࣮ݱɺ৴པੑΛ޲্ w 1VC4VCͱ֤ͯ͠ίϯϙʔωϯτͷؔ৺ࣄΛ෼཭ ศརʹ(PPHMF$MPVE1VC4VCΛར༻͢ΔͨΊʹ

    HDQDͱ͍͏HFNΛ࡞ͬͨ w IUUQTHJUIVCDPNTPVUIHDQD w ެࣜHFNΛXSBQͯ͠1MVHJOػߏ (SBDFGVMTIVUEPXOΛ௥Ճ w 1MVHJOͷDPMMFDUJPOΛIUUQTHJUIVCDPNTPVUIHDQDJOUFSDFQUPSTͱͯ͠ఏڙ