Class: Fluent::GcloudPubSub::Publisher
- Inherits:
-
Object
- Object
- Fluent::GcloudPubSub::Publisher
- Defined in:
- lib/fluent/plugin/gcloud_pubsub/client.rb
Instance Method Summary collapse
-
#initialize(project, key, topic, autocreate_topic) ⇒ Publisher
constructor
A new instance of Publisher.
- #publish(messages) ⇒ Object
Constructor Details
#initialize(project, key, topic, autocreate_topic) ⇒ Publisher
Returns a new instance of Publisher.
11 12 13 14 15 16 |
# File 'lib/fluent/plugin/gcloud_pubsub/client.rb', line 11 def initialize(project, key, topic, autocreate_topic) pubsub = Google::Cloud::Pubsub.new project: project, keyfile: key @client = pubsub.topic topic, autocreate: autocreate_topic raise Error.new "topic:#{topic} does not exist." if @client.nil? end |
Instance Method Details
#publish(messages) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/fluent/plugin/gcloud_pubsub/client.rb', line 18 def publish() @client.publish do |batch| .each do |m| batch.publish m end end rescue Google::Cloud::UnavailableError, Google::Cloud::DeadlineExceededError => ex raise RetryableError.new "Google api returns error:#{ex.class.to_s} message:#{ex.to_s}" end |