Sha256: 15095e72b456d7572aaf08407de8d90917ee28d0383b567f047695d271c1a805

Contents?: true

Size: 540 Bytes

Versions: 6

Compression:

Stored size: 540 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
    @google_cloud_pubsub ||= Google::Cloud::Pubsub.new
  end

  def call(env)
    @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

6 entries across 6 versions & 1 rubygems

Version Path
google-pubsub-enhancer-0.4.0 lib/google_pubsub_enhancer/middleware/publisher.rb
google-pubsub-enhancer-0.3.0 lib/google_pubsub_enhancer/middleware/publisher.rb
google-pubsub-enhancer-0.2.1 lib/google_pubsub_enhancer/middleware/publisher.rb
google-pubsub-enhancer-0.2.0 lib/google_pubsub_enhancer/middleware/publisher.rb
google-pubsub-enhancer-0.1.5 lib/google_pubsub_enhancer/middleware/publisher.rb
google-pubsub-enhancer-0.1.4 lib/google_pubsub_enhancer/middleware/publisher.rb