Class: Osbourne::Message
- Inherits:
-
Object
- Object
- Osbourne::Message
- Defined in:
- lib/osbourne/message.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes the message from SQS to prevent retrying against another worker.
-
#id ⇒ String
Osbourne has built-in message deduplication, but it’s still a good idea to do some verification in a worker.
-
#initialize(message) ⇒ Message
constructor
A new instance of Message.
-
#json? ⇒ Boolean
This will be
trueif the SNS message is also JSON. -
#message_body ⇒ Hash, ...
If the message was broadcast via SNS, the body will be available here.
-
#raw_body ⇒ String
The raw string representation of the message.
-
#sns? ⇒ Boolean
Just because a message was recieved via SQS, doesn’t mean it was originally broadcast via SNS.
-
#topic ⇒ String?
The SNS topic that this message was broadcast to.
-
#valid? ⇒ Boolean
Does the message match the checksum? If not, the message has likely been mangled in transit.
Constructor Details
#initialize(message) ⇒ Message
Returns a new instance of Message.
11 12 13 |
# File 'lib/osbourne/message.rb', line 11 def initialize() @message = end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
10 11 12 |
# File 'lib/osbourne/message.rb', line 10 def @message end |
Instance Method Details
#delete ⇒ Object
Deletes the message from SQS to prevent retrying against another worker. Osbourne will automatically delete a message sent to a worker as long as the Osourbne::WorkerBase#process method returns true
54 55 56 57 |
# File 'lib/osbourne/message.rb', line 54 def delete .delete Osbourne.logger.info "[Osbourne] [MSG ID: #{id}] Cleared" end |
#id ⇒ String
Osbourne has built-in message deduplication, but it’s still a good idea to do some verification in a worker
35 36 37 |
# File 'lib/osbourne/message.rb', line 35 def id . end |
#json? ⇒ Boolean
Returns This will be true if the SNS message is also JSON.
18 19 20 21 22 |
# File 'lib/osbourne/message.rb', line 18 def json? return false unless valid? sns_body.is_a?(Hash) end |
#message_body ⇒ Hash, ...
If the message was broadcast via SNS, the body will be available here.
46 47 48 |
# File 'lib/osbourne/message.rb', line 46 def sns_body end |
#raw_body ⇒ String
Returns The raw string representation of the message.
71 72 73 |
# File 'lib/osbourne/message.rb', line 71 def raw_body .body end |
#sns? ⇒ Boolean
Just because a message was recieved via SQS, doesn’t mean it was originally broadcast via SNS
78 79 80 |
# File 'lib/osbourne/message.rb', line 78 def sns? json_body.is_a?(Hash) && (%w[Message Type TopicArn MessageId] - json_body.keys).empty? end |
#topic ⇒ String?
The SNS topic that this message was broadcast to
63 64 65 66 67 |
# File 'lib/osbourne/message.rb', line 63 def topic return nil unless sns? json_body["TopicArn"].split(":").last end |
#valid? ⇒ Boolean
Does the message match the checksum? If not, the message has likely been mangled in transit
27 28 29 |
# File 'lib/osbourne/message.rb', line 27 def valid? @valid ||= .md5_of_body == Digest::MD5.hexdigest(.body) end |