You are viewing documentation for version 3 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: Aws::SQS::Message

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb

Defined Under Namespace

Classes: Collection

Actions collapse

Associations collapse

Read-Only Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue_url, receipt_handle, options = {}) ⇒ Message #initialize(options = {}) ⇒ Message

Returns a new instance of Message

Overloads:

  • #initialize(queue_url, receipt_handle, options = {}) ⇒ Message

    Parameters:

    • queue_url (String)
    • receipt_handle (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ Message

    Options Hash (options):

    • :queue_url (required, String)
    • :receipt_handle (required, String)
    • :client (Client)


21
22
23
24
25
26
27
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 21

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @queue_url = extract_queue_url(args, options)
  @receipt_handle = extract_receipt_handle(args, options)
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
end

Instance Method Details

#attributesHash<String,String>

SenderId, SentTimestamp, ApproximateReceiveCount, and/or ApproximateFirstReceiveTimestamp. SentTimestamp and ApproximateFirstReceiveTimestamp are each returned as an integer representing the epoch time in milliseconds.

Returns:

  • (Hash<String,String>)


69
70
71
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 69

def attributes
  data.attributes
end

#bodyString

The message's contents (not URL-encoded).

Returns:

  • (String)


56
57
58
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 56

def body
  data.body
end

#change_visibility(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


message.change_visibility({
  visibility_timeout: 1, # required
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :visibility_timeout (required, Integer)

    The new value for the message's visibility timeout (in seconds). Values values: 0 to 43200. Maximum: 12 hours.

Returns:

  • (EmptyStructure)


140
141
142
143
144
145
146
147
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 140

def change_visibility(options = {})
  options = options.merge(
    queue_url: @queue_url,
    receipt_handle: @receipt_handle
  )
  resp = @client.change_message_visibility(options)
  resp.data
end

#clientClient

Returns:



101
102
103
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 101

def client
  @client
end

#dataTypes::Message

Returns the data for this Aws::SQS::Message.

Returns:

Raises:



116
117
118
119
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 116

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.

Returns:

  • (Boolean)

    Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.



124
125
126
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 124

def data_loaded?
  !!@data
end

#delete(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


message.delete()

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Returns:

  • (EmptyStructure)


154
155
156
157
158
159
160
161
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 154

def delete(options = {})
  options = options.merge(
    queue_url: @queue_url,
    receipt_handle: @receipt_handle
  )
  resp = @client.delete_message(options)
  resp.data
end

#md5_of_bodyString

An MD5 digest of the non-URL-encoded message body string.

Returns:

  • (String)


50
51
52
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 50

def md5_of_body
  data.md5_of_body
end

#md5_of_message_attributesString

An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For information about MD5, see RFC1321.

Returns:

  • (String)


82
83
84
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 82

def md5_of_message_attributes
  data.md5_of_message_attributes
end

#message_attributesHash<String,Types::MessageAttributeValue>

Each message attribute consists of a Name, Type, and Value. For more information, see Message Attribute Items and Validation in the Amazon SQS Developer Guide.

Returns:



94
95
96
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 94

def message_attributes
  data.message_attributes
end

#message_idString

A unique identifier for the message. A MessageIdis considered unique across all AWS accounts for an extended period of time.

Returns:

  • (String)


44
45
46
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 44

def message_id
  data.message_id
end

#queueQueue

Returns:



166
167
168
169
170
171
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 166

def queue
  Queue.new(
    url: @queue_url,
    client: @client
  )
end

#queue_urlString

Returns:

  • (String)


32
33
34
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 32

def queue_url
  @queue_url
end

#receipt_handleString

Returns:

  • (String)


37
38
39
# File 'gems/aws-sdk-sqs/lib/aws-sdk-sqs/message.rb', line 37

def receipt_handle
  @receipt_handle
end