Class: Shoryuken::Message
- Inherits:
-
Object
- Object
- Shoryuken::Message
- Extended by:
- Forwardable
- Defined in:
- lib/shoryuken/message.rb
Overview
Represents an SQS message received by a Shoryuken worker. This class wraps the raw AWS SQS message data and provides convenient methods for interacting with the message, including deletion and visibility timeout management.
Message instances are automatically created by Shoryuken and passed to your worker’s ‘perform` method as the first argument.
Instance Attribute Summary collapse
-
#client ⇒ Aws::SQS::Client
The SQS client used for message operations.
-
#data ⇒ Aws::SQS::Types::Message
The raw SQS message data.
-
#queue_name ⇒ String
The name of the queue this message came from.
-
#queue_url ⇒ String
The URL of the SQS queue this message came from.
Instance Method Summary collapse
-
#attributes ⇒ Hash
Returns the SQS message attributes (system attributes).
-
#body ⇒ String
Returns the raw message body as received from SQS.
-
#change_visibility(options) ⇒ Aws::SQS::Types::ChangeMessageVisibilityResult
Changes the visibility timeout of this message with additional options.
-
#delete ⇒ Aws::SQS::Types::DeleteMessageResult
Deletes this message from the SQS queue.
-
#initialize(client, queue, data) ⇒ Message
constructor
private
Creates a new Message instance wrapping SQS message data.
-
#md5_of_body ⇒ String
Returns the MD5 hash of the message body.
-
#md5_of_message_attributes ⇒ String
Returns the MD5 hash of the message attributes.
-
#message_attributes ⇒ Hash
Returns custom message attributes set by the sender.
-
#message_id ⇒ String
Returns the unique SQS message ID.
-
#receipt_handle ⇒ String
Returns the receipt handle needed for deleting or modifying the message.
-
#visibility_timeout=(timeout) ⇒ Aws::SQS::Types::ChangeMessageVisibilityResult
Sets the visibility timeout for this message.
Constructor Details
#initialize(client, queue, data) ⇒ Message
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new Message instance wrapping SQS message data.
95 96 97 98 99 100 |
# File 'lib/shoryuken/message.rb', line 95 def initialize(client, queue, data) self.client = client self.data = data self.queue_url = queue.url self.queue_name = queue.name end |
Instance Attribute Details
#client ⇒ Aws::SQS::Client
Returns The SQS client used for message operations.
78 79 80 |
# File 'lib/shoryuken/message.rb', line 78 def client @client end |
#data ⇒ Aws::SQS::Types::Message
Returns The raw SQS message data.
87 88 89 |
# File 'lib/shoryuken/message.rb', line 87 def data @data end |
#queue_name ⇒ String
Returns The name of the queue this message came from.
84 85 86 |
# File 'lib/shoryuken/message.rb', line 84 def queue_name @queue_name end |
#queue_url ⇒ String
Returns The URL of the SQS queue this message came from.
81 82 83 |
# File 'lib/shoryuken/message.rb', line 81 def queue_url @queue_url end |
Instance Method Details
#attributes ⇒ Hash
Returns the SQS message attributes (system attributes).
68 69 70 71 72 73 74 75 |
# File 'lib/shoryuken/message.rb', line 68 def_delegators(:data, :message_id, :receipt_handle, :md5_of_body, :body, :attributes, :md5_of_message_attributes, :message_attributes) |
#body ⇒ String
Returns the raw message body as received from SQS.
68 69 70 71 72 73 74 75 |
# File 'lib/shoryuken/message.rb', line 68 def_delegators(:data, :message_id, :receipt_handle, :md5_of_body, :body, :attributes, :md5_of_message_attributes, :message_attributes) |
#change_visibility(options) ⇒ Aws::SQS::Types::ChangeMessageVisibilityResult
Changes the visibility timeout of this message with additional options. This allows you to hide the message from other consumers for a longer or shorter period.
127 128 129 130 131 |
# File 'lib/shoryuken/message.rb', line 127 def change_visibility() client.( .merge(queue_url: queue_url, receipt_handle: data.receipt_handle) ) end |
#delete ⇒ Aws::SQS::Types::DeleteMessageResult
Deletes this message from the SQS queue. Once deleted, the message will not be redelivered and cannot be retrieved again. This is typically called after successful message processing when auto_delete is disabled.
108 109 110 111 112 113 |
# File 'lib/shoryuken/message.rb', line 108 def delete client.( queue_url: queue_url, receipt_handle: data.receipt_handle ) end |
#md5_of_body ⇒ String
Returns the MD5 hash of the message body.
68 69 70 71 72 73 74 75 |
# File 'lib/shoryuken/message.rb', line 68 def_delegators(:data, :message_id, :receipt_handle, :md5_of_body, :body, :attributes, :md5_of_message_attributes, :message_attributes) |
#md5_of_message_attributes ⇒ String
Returns the MD5 hash of the message attributes.
68 69 70 71 72 73 74 75 |
# File 'lib/shoryuken/message.rb', line 68 def_delegators(:data, :message_id, :receipt_handle, :md5_of_body, :body, :attributes, :md5_of_message_attributes, :message_attributes) |
#message_attributes ⇒ Hash
Returns custom message attributes set by the sender.
68 69 70 71 72 73 74 75 |
# File 'lib/shoryuken/message.rb', line 68 def_delegators(:data, :message_id, :receipt_handle, :md5_of_body, :body, :attributes, :md5_of_message_attributes, :message_attributes) |
#message_id ⇒ String
Returns the unique SQS message ID.
68 69 70 71 72 73 74 75 |
# File 'lib/shoryuken/message.rb', line 68 def_delegators(:data, :message_id, :receipt_handle, :md5_of_body, :body, :attributes, :md5_of_message_attributes, :message_attributes) |
#receipt_handle ⇒ String
Returns the receipt handle needed for deleting or modifying the message.
68 69 70 71 72 73 74 75 |
# File 'lib/shoryuken/message.rb', line 68 def_delegators(:data, :message_id, :receipt_handle, :md5_of_body, :body, :attributes, :md5_of_message_attributes, :message_attributes) |
#visibility_timeout=(timeout) ⇒ Aws::SQS::Types::ChangeMessageVisibilityResult
Sets the visibility timeout for this message. This is a convenience method for changing only the visibility timeout.
151 152 153 154 155 156 157 |
# File 'lib/shoryuken/message.rb', line 151 def visibility_timeout=(timeout) client.( queue_url: queue_url, receipt_handle: data.receipt_handle, visibility_timeout: timeout ) end |