Class: BBK::HTTP::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, headers, payload, delivery_info: {}, protocol: nil) ⇒ Message

Returns a new instance of Message.



10
11
12
13
14
15
16
17
# File 'lib/bbk/http/message.rb', line 10

def initialize(consumer, headers, payload, delivery_info: {}, protocol: nil)
  @consumer = consumer
  @headers = headers.with_indifferent_access
  @payload = payload
  @payload = @payload.with_indifferent_access if @payload.is_a?(Hash)
  @delivery_info = delivery_info
  @protocol = protocol
end

Instance Attribute Details

#consumerObject (readonly)

Returns the value of attribute consumer.



7
8
9
# File 'lib/bbk/http/message.rb', line 7

def consumer
  @consumer
end

#delivery_infoObject (readonly)

Returns the value of attribute delivery_info.



7
8
9
# File 'lib/bbk/http/message.rb', line 7

def delivery_info
  @delivery_info
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/bbk/http/message.rb', line 7

def headers
  @headers
end

#payloadObject (readonly) Also known as: body

Returns the value of attribute payload.



7
8
9
# File 'lib/bbk/http/message.rb', line 7

def payload
  @payload
end

Instance Method Details

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



35
36
37
# File 'lib/bbk/http/message.rb', line 35

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

#cloneObject



43
44
45
# File 'lib/bbk/http/message.rb', line 43

def clone
  self.class.new(@consumer, headers, payload, protocol: @protocol)
end

#message_idObject



19
20
21
# File 'lib/bbk/http/message.rb', line 19

def message_id
  headers[:message_id]
end

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



39
40
41
# File 'lib/bbk/http/message.rb', line 39

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

#protocolObject



31
32
33
# File 'lib/bbk/http/message.rb', line 31

def protocol
  @protocol.presence || @consumer&.protocols&.first
end

#reply_toObject



23
24
25
# File 'lib/bbk/http/message.rb', line 23

def reply_to
  headers[:reply_to]
end

#user_idObject



27
28
29
# File 'lib/bbk/http/message.rb', line 27

def user_id
  headers[:user_id]
end