Class: Gcloud::Pubsub::ReceivedMessage
- Inherits:
-
Object
- Object
- Gcloud::Pubsub::ReceivedMessage
- Defined in:
- lib/gcloud/pubsub/received_message.rb
Overview
Instance Attribute Summary collapse
-
#gapi ⇒ Object
The Google API Client object.
-
#subscription ⇒ Object
The Subscription object.
Class Method Summary collapse
-
.from_gapi(gapi, subscription) ⇒ Object
New ReceivedMessage from a Google API Client object.
Instance Method Summary collapse
-
#ack_id ⇒ Object
The acknowledgment ID for the message.
-
#acknowledge! ⇒ Object
(also: #ack!)
Acknowledges receipt of the message.
-
#attributes ⇒ Object
The received message’s attributes.
-
#data ⇒ Object
The received message’s data.
-
#delay!(new_deadline) ⇒ Object
Modifies the acknowledge deadline for the message.
-
#initialize ⇒ ReceivedMessage
constructor
Create an empty Subscription object.
-
#message ⇒ Object
(also: #msg)
The received message.
-
#message_id ⇒ Object
(also: #msg_id)
The ID of the received message, assigned by the server at publication time.
Constructor Details
#initialize ⇒ ReceivedMessage
Create an empty Subscription object.
49 50 51 52 |
# File 'lib/gcloud/pubsub/received_message.rb', line 49 def initialize #:nodoc: @subscription = nil @gapi = {} end |
Instance Attribute Details
#gapi ⇒ Object
The Google API Client object.
45 46 47 |
# File 'lib/gcloud/pubsub/received_message.rb', line 45 def gapi @gapi end |
#subscription ⇒ Object
The Subscription object.
41 42 43 |
# File 'lib/gcloud/pubsub/received_message.rb', line 41 def subscription @subscription end |
Class Method Details
.from_gapi(gapi, subscription) ⇒ Object
New ReceivedMessage from a Google API Client object.
154 155 156 157 158 159 |
# File 'lib/gcloud/pubsub/received_message.rb', line 154 def self.from_gapi gapi, subscription #:nodoc: new.tap do |f| f.gapi = gapi f.subscription = subscription end end |
Instance Method Details
#ack_id ⇒ Object
The acknowledgment ID for the message.
56 57 58 |
# File 'lib/gcloud/pubsub/received_message.rb', line 56 def ack_id @gapi["ackId"] end |
#acknowledge! ⇒ Object Also known as: ack!
104 105 106 107 |
# File 'lib/gcloud/pubsub/received_message.rb', line 104 def acknowledge! ensure_subscription! subscription.acknowledge ack_id end |
#attributes ⇒ Object
The received message’s attributes.
75 76 77 |
# File 'lib/gcloud/pubsub/received_message.rb', line 75 def attributes .attributes end |
#data ⇒ Object
The received message’s data.
69 70 71 |
# File 'lib/gcloud/pubsub/received_message.rb', line 69 def data .data end |
#delay!(new_deadline) ⇒ Object
Modifies the acknowledge deadline for the message.
This indicates that more time is needed to process the message, or to make the message available for redelivery.
Parameters
deadline
-
The new ack deadline in seconds from the time this request is sent to the Pub/Sub system. Must be >= 0. For example, if the value is
10
, the new ack deadline will expire 10 seconds after the call is made. Specifying0
may immediately make the message available for another pull request. (Integer
)
Example
require "gcloud"
gcloud = Gcloud.new
pubsub = gcloud.pubsub
sub = pubsub.subscription "my-topic-sub"
= sub.pull.first
if
puts ..data
# Delay for 2 minutes
.delay! 120
end
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/gcloud/pubsub/received_message.rb', line 140 def delay! new_deadline ensure_subscription! connection = subscription.connection resp = connection.modify_ack_deadline subscription.name, ack_id, new_deadline if resp.success? true else fail ApiError.from_response(resp) end end |
#message ⇒ Object Also known as: msg
The received message.
62 63 64 |
# File 'lib/gcloud/pubsub/received_message.rb', line 62 def Message.from_gapi @gapi["message"] end |
#message_id ⇒ Object Also known as: msg_id
The ID of the received message, assigned by the server at publication time. Guaranteed to be unique within the topic.
82 83 84 |
# File 'lib/gcloud/pubsub/received_message.rb', line 82 def . end |