Class: BBK::AMQP::Message
- Inherits:
-
BBK::App::Dispatcher::Message
- Object
- BBK::App::Dispatcher::Message
- BBK::AMQP::Message
- Defined in:
- lib/bbk/amqp/message.rb
Overview
Store information about consumed AMQP message
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
- #clone ⇒ Object
-
#initialize(consumer, delivery_info, properties, body) ⇒ Message
constructor
A new instance of Message.
-
#inspect ⇒ Object
:nodoc:.
- #marshal_dump ⇒ Object
- #marshal_load(array) ⇒ Object
- #message_id ⇒ Object
- #protocol ⇒ Object
- #reply_to ⇒ Object
- #user_id ⇒ Object
Constructor Details
#initialize(consumer, delivery_info, properties, body) ⇒ Message
Returns a new instance of Message.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bbk/amqp/message.rb', line 12 def initialize(consumer, delivery_info, properties, body) @properties = properties.to_h.with_indifferent_access headers = @properties.except(:headers).merge(@properties[:headers].presence || {}).with_indifferent_access if (t = headers[:timestamp]).present? headers[:timestamp] = t.to_i end amqp_consumer = delivery_info[:consumer] delivery_info = delivery_info.to_h.merge( message_consumer: consumer, protocols: consumer.protocols, queue: amqp_consumer&.queue_name ) super(consumer, delivery_info, headers, body) end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
10 11 12 |
# File 'lib/bbk/amqp/message.rb', line 10 def properties @properties end |
Instance Method Details
#clone ⇒ Object
41 42 43 |
# File 'lib/bbk/amqp/message.rb', line 41 def clone self.class.new(consumer, delivery_info, properties, body) end |
#inspect ⇒ Object
:nodoc:
49 50 51 |
# File 'lib/bbk/amqp/message.rb', line 49 def inspect # :nodoc: "#<#{self.class.name} @consumer=#{consumer.class.name}, @delivery_info=#{delivery_info.except(:message_consumer).inspect}, @headers=#{headers.inspect}, @properties=#{@properties.inspect}>" end |
#marshal_dump ⇒ Object
53 54 55 |
# File 'lib/bbk/amqp/message.rb', line 53 def marshal_dump [@properties] + super end |
#marshal_load(array) ⇒ Object
57 58 59 60 |
# File 'lib/bbk/amqp/message.rb', line 57 def marshal_load(array) @properties, *parent_attributes = array super(parent_attributes) end |
#message_id ⇒ Object
29 30 31 |
# File 'lib/bbk/amqp/message.rb', line 29 def headers[:message_id] end |
#protocol ⇒ Object
45 46 47 |
# File 'lib/bbk/amqp/message.rb', line 45 def protocol consumer&.protocols&.first end |
#reply_to ⇒ Object
33 34 35 |
# File 'lib/bbk/amqp/message.rb', line 33 def reply_to headers[:reply_to] || user_id end |
#user_id ⇒ Object
37 38 39 |
# File 'lib/bbk/amqp/message.rb', line 37 def user_id headers[:user_id] end |