Class: Gcloud::Pubsub::ReceivedMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/pubsub/received_message.rb

Overview

ReceivedMessage

Represents a Pub/Sub Message that can be acknowledged or delayed.

Examples:

require "gcloud"

gcloud = Gcloud.new
pubsub = gcloud.pubsub

sub = pubsub.subscription "my-topic-sub"
received_message = sub.pull.first
if received_message
  puts received_message.message.data
  received_message.acknowledge!
end

Instance Method Summary collapse

Instance Method Details

#ack_idObject

The acknowledgment ID for the message.


57
58
59
# File 'lib/gcloud/pubsub/received_message.rb', line 57

def ack_id
  @gapi["ackId"]
end

#acknowledge!Object Also known as: ack!

Acknowledges receipt of the message.

Examples:

require "gcloud"

gcloud = Gcloud.new
pubsub = gcloud.pubsub

sub = pubsub.subscription "my-topic-sub"
received_message = sub.pull.first
if received_message
  puts received_message.message.data
  received_message.acknowledge!
end

104
105
106
107
# File 'lib/gcloud/pubsub/received_message.rb', line 104

def acknowledge!
  ensure_subscription!
  subscription.acknowledge ack_id
end

#attributesObject

The received message's attributes.


76
77
78
# File 'lib/gcloud/pubsub/received_message.rb', line 76

def attributes
  message.attributes
end

#dataObject

The received message's data.


70
71
72
# File 'lib/gcloud/pubsub/received_message.rb', line 70

def data
  message.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.

Examples:

require "gcloud"

gcloud = Gcloud.new
pubsub = gcloud.pubsub

sub = pubsub.subscription "my-topic-sub"
received_message = sub.pull.first
if received_message
  puts received_message.message.data
  # Delay for 2 minutes
  received_message.delay! 120
end

136
137
138
139
140
141
142
143
144
145
146
# File 'lib/gcloud/pubsub/received_message.rb', line 136

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

#messageObject Also known as: msg

The received message.


63
64
65
# File 'lib/gcloud/pubsub/received_message.rb', line 63

def message
  Message.from_gapi @gapi["message"]
end

#message_idObject 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.


83
84
85
# File 'lib/gcloud/pubsub/received_message.rb', line 83

def message_id
  message.message_id
end