Class: Msgr::Message
- Inherits:
-
Object
- Object
- Msgr::Message
- Defined in:
- lib/msgr/message.rb
Instance Attribute Summary collapse
-
#delivery_info ⇒ Object
readonly
Returns the value of attribute delivery_info.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#route ⇒ Object
readonly
Returns the value of attribute route.
Instance Method Summary collapse
-
#ack ⇒ Object
Send message acknowledge to broker unless message is already acknowledged.
-
#acked? ⇒ Boolean
Check if message is already acknowledged.
- #content_type ⇒ Object
-
#initialize(channel, delivery_info, metadata, payload, route) ⇒ Message
constructor
A new instance of Message.
-
#nack ⇒ Object
Send negative message acknowledge to broker unless message is already acknowledged.
Constructor Details
#initialize(channel, delivery_info, metadata, payload, route) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/msgr/message.rb', line 7 def initialize(channel, delivery_info, , payload, route) @channel = channel @delivery_info = delivery_info @metadata = @payload = payload @route = route if content_type == 'application/json' # rubocop:disable Style/GuardClause @payload = JSON.parse(payload) @payload.symbolize_keys! if @payload.respond_to? :symbolize_keys! end end |
Instance Attribute Details
#delivery_info ⇒ Object (readonly)
Returns the value of attribute delivery_info.
5 6 7 |
# File 'lib/msgr/message.rb', line 5 def delivery_info @delivery_info end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
5 6 7 |
# File 'lib/msgr/message.rb', line 5 def @metadata end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/msgr/message.rb', line 5 def payload @payload end |
#route ⇒ Object (readonly)
Returns the value of attribute route.
5 6 7 |
# File 'lib/msgr/message.rb', line 5 def route @route end |
Instance Method Details
#ack ⇒ Object
Send message acknowledge to broker unless message is already acknowledged.
38 39 40 41 42 43 |
# File 'lib/msgr/message.rb', line 38 def ack return if acked? @acked = true @channel.ack delivery_info.delivery_tag end |
#acked? ⇒ Boolean
Check if message is already acknowledged.
29 30 31 |
# File 'lib/msgr/message.rb', line 29 def acked? @acked ? true : false end |
#content_type ⇒ Object
20 21 22 |
# File 'lib/msgr/message.rb', line 20 def content_type @metadata.content_type end |
#nack ⇒ Object
Send negative message acknowledge to broker unless message is already acknowledged.
50 51 52 53 54 55 |
# File 'lib/msgr/message.rb', line 50 def nack return if acked? @acked = true @channel.nack delivery_info.delivery_tag end |