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

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

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.



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

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/bbk/app/dispatcher/message.rb', line 6

def body
  @body
end

#consumerObject (readonly)

Returns the value of attribute consumer.



6
7
8
# File 'lib/bbk/app/dispatcher/message.rb', line 6

def consumer
  @consumer
end

#delivery_infoObject (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

#headersObject (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_idObject

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/bbk/app/dispatcher/message.rb', line 32

def message_id
  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

#payloadObject

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 reply_message_id(addon)
  Digest::SHA1.hexdigest("#{addon}#{message_id}")
end

#reply_toObject

Raises:

  • (NotImplementedError)


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_hObject



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

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

#user_idObject

Raises:

  • (NotImplementedError)


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