Sha256: 2d551b086bf435ba0509a3dddbeb48f5fbd93215ea7e50d0e5933636a8cb2324

Contents?: true

Size: 659 Bytes

Versions: 2

Compression:

Stored size: 659 Bytes

Contents

class GooglePubsubEnhancer::Middleware::Publisher

  def initialize(app, opts={})
    @app = app
    @short_topic_name = opts[:short_topic_name] || raise
    @full_topic_name = GooglePubsubEnhancer.name_by('topics',@short_topic_name)
    @messages_key = opts[:messages] || raise
    @logger = opts[:logger] || Logger.new(STDOUT)
    @google_cloud_pubsub ||= Google::Cloud::Pubsub.new
  end

  def call(env)
    @logger.debug("#{env[@messages_key].length} messages published")
    @google_cloud_pubsub.publish(@full_topic_name) do |publisher|
      [*env[@messages_key]].each do |m|
        publisher.publish(m)
      end
    end
    @app.call(env)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
google-pubsub-enhancer-0.4.2 lib/google_pubsub_enhancer/middleware/publisher.rb
google-pubsub-enhancer-0.4.1 lib/google_pubsub_enhancer/middleware/publisher.rb