Class: Bisques::Message
- Inherits:
-
Object
- Object
- Bisques::Message
- Defined in:
- lib/bisques/message.rb
Overview
A message received from an SQS queue.
Constant Summary collapse
- InvalidObjectError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
Hash of SQS attributes.
-
#body ⇒ String
readonly
The raw text body of the message.
-
#handle ⇒ String
readonly
A unique handle used to manipulate the message.
-
#id ⇒ String
readonly
The AWS Id of the message.
-
#queue ⇒ Queue
readonly
The queue this message originated from.
Instance Method Summary collapse
-
#delete ⇒ Boolean
Delete the message from the queue.
-
#initialize(queue, id, handle, body, attributes = {}) ⇒ Message
constructor
A new instance of Message.
-
#object ⇒ Object
The deserialized object in the message.
-
#return ⇒ AwsResponse
Return the message to the queue immediately.
Constructor Details
#initialize(queue, id, handle, body, attributes = {}) ⇒ Message
Returns a new instance of Message.
25 26 27 |
# File 'lib/bisques/message.rb', line 25 def initialize(queue, id, handle, body, attributes = {}) #:nodoc: @queue, @id, @handle, @body, @attributes = queue, id, handle, body, attributes end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns Hash of SQS attributes.
15 16 17 |
# File 'lib/bisques/message.rb', line 15 def attributes @attributes end |
#body ⇒ String (readonly)
Returns The raw text body of the message.
13 14 15 |
# File 'lib/bisques/message.rb', line 13 def body @body end |
#handle ⇒ String (readonly)
Returns A unique handle used to manipulate the message.
11 12 13 |
# File 'lib/bisques/message.rb', line 11 def handle @handle end |
#id ⇒ String (readonly)
Returns The AWS Id of the message.
9 10 11 |
# File 'lib/bisques/message.rb', line 9 def id @id end |
#queue ⇒ Queue (readonly)
Returns The queue this message originated from.
7 8 9 |
# File 'lib/bisques/message.rb', line 7 def queue @queue end |
Instance Method Details
#delete ⇒ Boolean
Delete the message from the queue. This should be called after the message has been received and processed. If not then after a timeout the message will get added back to the queue.
48 49 50 |
# File 'lib/bisques/message.rb', line 48 def delete queue.(handle) end |
#object ⇒ Object
The deserialized object in the message. This method is used to retrieve the contents that Queue#post_message placed there.
37 38 39 40 41 |
# File 'lib/bisques/message.rb', line 37 def object @object ||= JSON.parse(body) rescue => error raise InvalidObjectError.new(error.to_s) end |
#return ⇒ AwsResponse
Return the message to the queue immediately. If a client has taken a message and cannot process it for any reason it can put the message back faster than the default timeout by calling this method.
57 58 59 |
# File 'lib/bisques/message.rb', line 57 def return queue.(handle) end |