Class: Fluent::GcloudPubSub::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/gcloud_pubsub/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(project, key, topic, autocreate_topic) ⇒ Publisher

Returns a new instance of Publisher.



8
9
10
11
12
13
# File 'lib/fluent/plugin/gcloud_pubsub/client.rb', line 8

def initialize(project, key, topic, autocreate_topic)
  pubsub = (Google::Cloud.new project, key).pubsub

  @client = pubsub.topic topic, autocreate: autocreate_topic
  raise Fluent::GcloudPubSub::Error.new "topic:#{topic} does not exist." if @client.nil?
end

Instance Method Details

#publish(messages) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/fluent/plugin/gcloud_pubsub/client.rb', line 15

def publish(messages)
  @client.publish do |batch|
    messages.each do |m|
      batch.publish m
    end
  end
end