Class: Google::Cloud::Pubsub::ReceivedMessage

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

Overview

ReceivedMessage

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

Examples:

require "google/cloud"

gcloud = Google::Cloud.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.



58
59
60
# File 'lib/google/cloud/pubsub/received_message.rb', line 58

def ack_id
  @grpc.ack_id
end

#acknowledge!Object Also known as: ack!

Acknowledges receipt of the message.

Examples:

require "google/cloud"

gcloud = Google::Cloud.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


105
106
107
108
# File 'lib/google/cloud/pubsub/received_message.rb', line 105

def acknowledge!
  ensure_subscription!
  subscription.acknowledge ack_id
end

#attributesObject

The received message's attributes.



77
78
79
# File 'lib/google/cloud/pubsub/received_message.rb', line 77

def attributes
  message.attributes
end

#dataObject

The received message's data.



71
72
73
# File 'lib/google/cloud/pubsub/received_message.rb', line 71

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 "google/cloud"

gcloud = Google::Cloud.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

Parameters:

  • new_deadline (Integer)

    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. Specifying 0 may immediately make the message available for another pull request.



137
138
139
140
# File 'lib/google/cloud/pubsub/received_message.rb', line 137

def delay! new_deadline
  ensure_subscription!
  subscription.delay new_deadline, ack_id
end

#messageObject Also known as: msg

The received message.



64
65
66
# File 'lib/google/cloud/pubsub/received_message.rb', line 64

def message
  Message.from_grpc @grpc.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.



84
85
86
# File 'lib/google/cloud/pubsub/received_message.rb', line 84

def message_id
  message.message_id
end