Class: Gcloud::Pubsub::Message
- Inherits:
-
Object
- Object
- Gcloud::Pubsub::Message
- Defined in:
- lib/gcloud/pubsub/message.rb
Overview
Message
Represents a Pub/Sub Message.
Message objects are created by Topic#publish. Subscription#pull returns an array of ReceivedMessage objects, each of which contains a Message object. Each ReceivedMessage object can be acknowledged and/or delayed.
require "gcloud"
gcloud = Gcloud.new
pubsub = gcloud.pubsub
# Publish a message
topic = pubsub.topic "my-topic"
= topic.publish "new-message"
puts .data #=> "new-message"
# Pull a message
sub = pubsub.subscription "my-topic-sub"
= sub.pull.first
puts ..data #=> "new-message"
Instance Attribute Summary collapse
-
#gapi ⇒ Object
The Google API Client object.
Class Method Summary collapse
-
.from_gapi(gapi) ⇒ Object
New Topic from a Google API Client object.
Instance Method Summary collapse
-
#attributes ⇒ Object
The received attributes.
-
#data ⇒ Object
The received data.
-
#initialize(data = nil, attributes = {}) ⇒ Message
constructor
Create an empty Message object.
-
#message_id ⇒ Object
(also: #msg_id)
The ID of this message, assigned by the server at publication time.
Constructor Details
#initialize(data = nil, attributes = {}) ⇒ Message
Create an empty Message object. This can be used to publish several messages in bulk.
53 54 55 56 57 |
# File 'lib/gcloud/pubsub/message.rb', line 53 def initialize data = nil, attributes = {} @gapi = {} @gapi["data"] = data @gapi["attributes"] = attributes end |
Instance Attribute Details
#gapi ⇒ Object
The Google API Client object.
48 49 50 |
# File 'lib/gcloud/pubsub/message.rb', line 48 def gapi @gapi end |
Class Method Details
.from_gapi(gapi) ⇒ Object
New Topic from a Google API Client object.
83 84 85 86 87 |
# File 'lib/gcloud/pubsub/message.rb', line 83 def self.from_gapi gapi #:nodoc: new.tap do |f| f.gapi = gapi end end |
Instance Method Details
#attributes ⇒ Object
The received attributes.
67 68 69 70 71 |
# File 'lib/gcloud/pubsub/message.rb', line 67 def attributes attrs = @gapi["attributes"] attrs = attrs.to_hash if attrs.respond_to? :to_hash attrs end |
#data ⇒ Object
The received data.
61 62 63 |
# File 'lib/gcloud/pubsub/message.rb', line 61 def data @gapi["data"] end |
#message_id ⇒ Object Also known as: msg_id
The ID of this message, assigned by the server at publication time. Guaranteed to be unique within the topic.
76 77 78 |
# File 'lib/gcloud/pubsub/message.rb', line 76 def @gapi["messageId"] end |