Class: Pebbles::River::Message
- Inherits:
-
Object
- Object
- Pebbles::River::Message
- Defined in:
- lib/pebbles/river/message.rb
Instance Attribute Summary collapse
-
#delivery_info ⇒ Object
readonly
Returns the value of attribute delivery_info.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #ack ⇒ Object
- #delivery_tag ⇒ Object
-
#initialize(content, delivery_info, queue = nil) ⇒ Message
constructor
A new instance of Message.
- #nack ⇒ Object
Constructor Details
#initialize(content, delivery_info, queue = nil) ⇒ Message
31 32 33 34 35 36 |
# File 'lib/pebbles/river/message.rb', line 31 def initialize(content, delivery_info, queue = nil) @queue = queue @delivery_info = delivery_info @payload = self.class.deserialize_payload(content) @replied = false end |
Instance Attribute Details
#delivery_info ⇒ Object (readonly)
Returns the value of attribute delivery_info.
19 20 21 |
# File 'lib/pebbles/river/message.rb', line 19 def delivery_info @delivery_info end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
17 18 19 |
# File 'lib/pebbles/river/message.rb', line 17 def payload @payload end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
18 19 20 |
# File 'lib/pebbles/river/message.rb', line 18 def queue @queue end |
Class Method Details
.deserialize_payload(content) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/pebbles/river/message.rb', line 21 def self.deserialize_payload(content) if content begin return JSON.parse(content) rescue => e raise InvalidPayloadError.new(e., content) end end end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 41 42 |
# File 'lib/pebbles/river/message.rb', line 38 def ==(other) other && other.is_a?(Message) && other.payload == @payload end |
#ack ⇒ Object
48 49 50 51 52 53 |
# File 'lib/pebbles/river/message.rb', line 48 def ack if !@replied && (tag = delivery_tag) @queue.channel.ack(tag) @replied = true end end |
#delivery_tag ⇒ Object
44 45 46 |
# File 'lib/pebbles/river/message.rb', line 44 def delivery_tag @delivery_info.delivery_tag if @delivery_info end |
#nack ⇒ Object
55 56 57 58 59 60 |
# File 'lib/pebbles/river/message.rb', line 55 def nack if !@replied && (tag = delivery_tag) @queue.channel.nack(tag, false, true) @replied = true end end |