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

Class: Aws::SQS::Message

Inherits:
Resources::Resource show all
Defined in:
(unknown)

Instance Attribute Summary collapse

Attributes inherited from Resources::Resource

#client, #identifiers

Instance Method Summary collapse

Methods inherited from Resources::Resource

add_data_attribute, add_identifier, #data, data_attributes, #data_loaded?, identifiers, #load, #wait_until

Methods included from Resources::OperationMethods

#add_batch_operation, #add_operation, #batch_operation, #batch_operation_names, #batch_operations, #operation, #operation_names, #operations

Constructor Details

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

Overloads:

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

    Parameters:

    • queue_url (String)
    • receipt_handle (String)

    Options Hash (options):

    • :client (Client)

      When `:client is not given, the options hash is used to construct a new Client object.

  • #initialize(options = {}) ⇒ Object

    Options Hash (options):

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

      When `:client is not given, the options hash is used to construct a new Client object.

Instance Attribute Details

#attributesHash<String,String> (readonly)

A map of the attributes requested in ReceiveMessage to their respective values. Supported attributes:

  • ApproximateReceiveCount

  • ApproximateFirstReceiveTimestamp

  • MessageDeduplicationId

  • MessageGroupId

  • SenderId

  • SentTimestamp

  • SequenceNumber

ApproximateFirstReceiveTimestamp and SentTimestamp are each returned as an integer representing the epoch time in milliseconds.

Returns:

  • (Hash<String,String>)

    A map of the attributes requested in ReceiveMessage to their respective values.

#bodyString (readonly)

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

Returns:

  • (String)

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

#md5_of_bodyString (readonly)

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

Returns:

  • (String)

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

#md5_of_message_attributesString (readonly)

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)

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

#message_attributesHash<String,Types::MessageAttributeValue> (readonly)

Each message attribute consists of a Name, Type, and Value. For more information, see Amazon SQS Message Attributes in the Amazon Simple Queue Service Developer Guide.

Returns:

#message_idString (readonly)

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

Returns:

  • (String)

    A unique identifier for the message.

#queue_urlString (readonly)

Returns:

  • (String)

#receipt_handleString (readonly)

Returns:

  • (String)

Instance Method Details

#change_visibility(options = {}) ⇒ Struct

Changes the visibility timeout of a specified message in a queue to a new value. The maximum allowed timeout value is 12 hours. For more information, see Visibility Timeout in the Amazon Simple Queue Service Developer Guide.

For example, you have a message with a visibility timeout of 5 minutes. After 3 minutes, you call ChangeMessageVisibility with a timeout of 10 minutes. You can continue to call ChangeMessageVisibility to extend the visibility timeout to a maximum of 12 hours. If you try to extend the visibility timeout beyond 12 hours, your request is rejected.

A message is considered to be in flight after it's received from a queue by a consumer, but not yet deleted from the queue.

For standard queues, there can be a maximum of 120,000 inflight messages per queue. If you reach this limit, Amazon SQS returns the OverLimit error message. To avoid reaching the limit, you should delete messages from the queue after they're processed. You can also increase the number of queues you use to process your messages.

For FIFO queues, there can be a maximum of 20,000 inflight messages per queue. If you reach this limit, Amazon SQS returns no error messages.

If you attempt to set the VisibilityTimeout to a value greater than the maximum time left, Amazon SQS returns an error. Amazon SQS doesn't automatically recalculate and increase the timeout to the maximum remaining time.

Unlike with a queue, when you change the visibility timeout for a specific message the timeout value is applied immediately but isn't saved in memory for that message. If you don't delete a message after it is received, the visibility timeout for the message reverts to the original timeout value (not to the value you set using the ChangeMessageVisibility action) the next time the message is received.

Examples:

Request syntax example with placeholder values


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

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:

  • (Struct)

    Returns an empty response.

See Also:

#deleteStruct

Deletes the specified message from the specified queue. To select the message to delete, use the ReceiptHandle of the message (not the MessageId which you receive when you send the message). Amazon SQS can delete a message from a queue even if a visibility timeout setting causes the message to be locked by another consumer. Amazon SQS automatically deletes messages left in a queue longer than the retention period configured for the queue.

The ReceiptHandle is associated with a specific instance of receiving a message. If you receive a message more than once, the ReceiptHandle is different each time you receive a message. When you use the DeleteMessage action, you must provide the most recently received ReceiptHandle for the message (otherwise, the request succeeds, but the message might not be deleted).

For standard queues, it is possible to receive a message even after you delete it. This might happen on rare occasions if one of the servers which stores a copy of the message is unavailable when you send the request to delete the message. The copy remains on the server and might be returned to you during a subsequent receive request. You should ensure that your application is idempotent, so that receiving a message more than once does not cause issues.

Examples:

Request syntax example with placeholder values


message.delete()

Returns:

  • (Struct)

    Returns an empty response.

See Also:

#queueQueue

Returns: