Class: BBK::App::Dispatcher::Message
- Inherits:
-
Object
- Object
- BBK::App::Dispatcher::Message
- Defined in:
- lib/bbk/app/dispatcher/message.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#consumer ⇒ Object
readonly
Returns the value of attribute consumer.
-
#delivery_info ⇒ Object
readonly
Returns the value of attribute delivery_info.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #ack(*args, answer: nil, **kwargs) ⇒ Object
-
#initialize(consumer, delivery_info, headers, body, *_args, **_kwargs) ⇒ Message
constructor
A new instance of Message.
- #message_id ⇒ Object
- #nack(*args, error: nil, **kwargs) ⇒ Object
-
#payload ⇒ Object
Lazy body parsing.
- #reply_message_id(addon) ⇒ Object
- #reply_to ⇒ Object
- #to_h ⇒ Object
- #user_id ⇒ Object
Constructor Details
#initialize(consumer, delivery_info, headers, body, *_args, **_kwargs) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 |
# File 'lib/bbk/app/dispatcher/message.rb', line 8 def initialize(consumer, delivery_info, headers, body, *_args, **_kwargs) @consumer = consumer @delivery_info = delivery_info @headers = headers.to_h.with_indifferent_access @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/bbk/app/dispatcher/message.rb', line 6 def body @body end |
#consumer ⇒ Object (readonly)
Returns the value of attribute consumer.
6 7 8 |
# File 'lib/bbk/app/dispatcher/message.rb', line 6 def consumer @consumer end |
#delivery_info ⇒ Object (readonly)
Returns the value of attribute delivery_info.
6 7 8 |
# File 'lib/bbk/app/dispatcher/message.rb', line 6 def delivery_info @delivery_info end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/bbk/app/dispatcher/message.rb', line 6 def headers @headers end |
Instance Method Details
#ack(*args, answer: nil, **kwargs) ⇒ Object
24 25 26 |
# File 'lib/bbk/app/dispatcher/message.rb', line 24 def ack(*args, answer: nil, **kwargs) consumer.ack(self, *args, answer: answer, **kwargs) end |
#message_id ⇒ Object
32 33 34 |
# File 'lib/bbk/app/dispatcher/message.rb', line 32 def raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method") end |
#nack(*args, error: nil, **kwargs) ⇒ Object
28 29 30 |
# File 'lib/bbk/app/dispatcher/message.rb', line 28 def nack(*args, error: nil, **kwargs) consumer.nack(self, *args, error: error, **kwargs) end |
#payload ⇒ Object
Lazy body parsing
16 17 18 19 20 21 22 |
# File 'lib/bbk/app/dispatcher/message.rb', line 16 def payload @payload ||= begin JSON.parse(@body).with_indifferent_access rescue StandardError {}.with_indifferent_access end end |
#reply_message_id(addon) ⇒ Object
44 45 46 |
# File 'lib/bbk/app/dispatcher/message.rb', line 44 def (addon) Digest::SHA1.hexdigest("#{addon}#{message_id}") end |
#reply_to ⇒ Object
36 37 38 |
# File 'lib/bbk/app/dispatcher/message.rb', line 36 def reply_to raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method") end |
#to_h ⇒ Object
48 49 50 51 52 53 |
# File 'lib/bbk/app/dispatcher/message.rb', line 48 def to_h { headers: headers, body: body } end |
#user_id ⇒ Object
40 41 42 |
# File 'lib/bbk/app/dispatcher/message.rb', line 40 def user_id raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method") end |