Class: BBK::App::Dispatcher::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/bbk/app/dispatcher/message.rb

Direct Known Subclasses

Spec::Dispatcher::Message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, delivery_info, headers, body, *_args, **_kwargs) ⇒ Message

Returns a new instance of Message.



10
11
12
13
14
15
# File 'lib/bbk/app/dispatcher/message.rb', line 10

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

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/bbk/app/dispatcher/message.rb', line 8

def body
  @body
end

#consumerObject (readonly)

Returns the value of attribute consumer.



8
9
10
# File 'lib/bbk/app/dispatcher/message.rb', line 8

def consumer
  @consumer
end

#delivery_infoObject (readonly)

Returns the value of attribute delivery_info.



8
9
10
# File 'lib/bbk/app/dispatcher/message.rb', line 8

def delivery_info
  @delivery_info
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/bbk/app/dispatcher/message.rb', line 8

def headers
  @headers
end

Instance Method Details

#ack(*args, answer: nil, **kwargs) ⇒ Object



26
27
28
# File 'lib/bbk/app/dispatcher/message.rb', line 26

def ack(*args, answer: nil, **kwargs)
  consumer.ack(self, *args, answer: answer, **kwargs)
end

#inspectObject

:nodoc:



61
62
63
# File 'lib/bbk/app/dispatcher/message.rb', line 61

def inspect # :nodoc:
  "#<#{self.class.name} @consumer=#{consumer.class.name}, @headers=#{headers.inspect}>"
end

#message_idObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/bbk/app/dispatcher/message.rb', line 34

def message_id
  raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method")
end

#nack(*args, error: nil, **kwargs) ⇒ Object



30
31
32
# File 'lib/bbk/app/dispatcher/message.rb', line 30

def nack(*args, error: nil, **kwargs)
  consumer.nack(self, *args, error: error, **kwargs)
end

#payloadObject

Lazy body parsing



18
19
20
21
22
23
24
# File 'lib/bbk/app/dispatcher/message.rb', line 18

def payload
  @payload ||= begin
    Oj.load(@body).with_indifferent_access
  rescue StandardError
    {}.with_indifferent_access
  end
end

#protocolObject

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/bbk/app/dispatcher/message.rb', line 46

def protocol
  raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method")
end

#reply_message_id(addon) ⇒ Object



50
51
52
# File 'lib/bbk/app/dispatcher/message.rb', line 50

def reply_message_id(addon)
  Digest::SHA1.hexdigest("#{addon}#{message_id}")
end

#reply_toObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/bbk/app/dispatcher/message.rb', line 38

def reply_to
  raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method")
end

#to_hObject



54
55
56
57
58
59
# File 'lib/bbk/app/dispatcher/message.rb', line 54

def to_h
  {
    headers: headers,
    body:    body
  }
end

#user_idObject

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/bbk/app/dispatcher/message.rb', line 42

def user_id
  raise NotImplementedError.new("#{self.class.name} does not implement #{__method__} method")
end