Class: Gcloud::Pubsub::Topic::Batch
- Inherits:
-
Object
- Object
- Gcloud::Pubsub::Topic::Batch
- Defined in:
- lib/gcloud/pubsub/topic.rb
Overview
Batch object used to publish multiple messages at once.
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
The messages to publish.
Instance Method Summary collapse
-
#initialize(data = nil, attributes = {}) ⇒ Batch
constructor
Create a new instance of the object.
-
#publish(data, attributes = {}) ⇒ Object
Add multiple messages to the topic.
-
#to_gcloud_messages(message_ids) ⇒ Object
Create Message objects with message ids.
Constructor Details
#initialize(data = nil, attributes = {}) ⇒ Batch
Create a new instance of the object.
591 592 593 594 595 596 597 |
# File 'lib/gcloud/pubsub/topic.rb', line 591 def initialize data = nil, attributes = {} #:nodoc: = [] @mode = :batch return if data.nil? @mode = :single publish data, attributes end |
Instance Attribute Details
#messages ⇒ Object (readonly)
The messages to publish
587 588 589 |
# File 'lib/gcloud/pubsub/topic.rb', line 587 def end |
Instance Method Details
#publish(data, attributes = {}) ⇒ Object
Add multiple messages to the topic. All messages added will be published at once. See Gcloud::Pubsub::Topic#publish
603 604 605 |
# File 'lib/gcloud/pubsub/topic.rb', line 603 def publish data, attributes = {} << [data, attributes] end |
#to_gcloud_messages(message_ids) ⇒ Object
Create Message objects with message ids.
609 610 611 612 613 614 615 616 617 618 619 620 621 622 |
# File 'lib/gcloud/pubsub/topic.rb', line 609 def #:nodoc: msgs = .zip(Array()).map do |arr, id| Message.from_gapi "data" => arr[0], "attributes" => jsonify_hash(arr[1]), "messageId" => id end # Return just one Message if a single publish, # otherwise return the array of Messages. if @mode == :single && msgs.count <= 1 msgs.first else msgs end end |