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 default visibility timeout for a message is 30 seconds. The minimum is 0 seconds. The maximum 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 the maximum allowed time. If you try to extend the visibility timeout beyond the maximum, your request is rejected.

An Amazon SQS message has three basic states:

  1. Sent to a queue by a producer.

  2. Received from the queue by a consumer.

  3. Deleted from the queue.

A message is considered to be stored after it is sent to a queue by a producer, but not yet received from the queue by a consumer (that is, between states 1 and 2). There is no limit to the number of stored messages. A message is considered to be in flight after it is received from a queue by a consumer, but not yet deleted from the queue (that is, between states 2 and 3). There is a limit to the number of inflight messages.

Limits that apply to inflight messages are unrelated to the unlimited number of stored messages.

For most standard queues (depending on queue traffic and message backlog), there can be a maximum of approximately 120,000 inflight messages (received from a queue by a consumer, but not yet deleted from the 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. To request a limit increase, file a support request.

For FIFO queues, there can be a maximum of 20,000 inflight messages (received from a queue by a consumer, but not yet deleted from the 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 range: 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: