Class: Google::Cloud::Pubsub::BatchPublisher

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/pubsub/batch_publisher.rb

Overview

Topic Batch Publisher object used to publish multiple messages at once.

Examples:

require "google/cloud/pubsub"

pubsub = Google::Cloud::Pubsub.new

topic = pubsub.topic "my-topic"
msgs = topic.publish do |t|
  t.publish "task 1 completed", foo: :bar
  t.publish "task 2 completed", foo: :baz
  t.publish "task 3 completed", foo: :bif
end

Instance Method Summary collapse

Instance Method Details

#publish(data, attributes = {}) ⇒ Object

Add a message to the batch to be published to the topic. All messages added to the batch will be published at once. See Topic#publish



53
54
55
# File 'lib/google/cloud/pubsub/batch_publisher.rb', line 53

def publish data, attributes = {}
  @messages << create_pubsub_message(data, attributes)
end