Class: BBK::AMQP::Message

Inherits:
BBK::App::Dispatcher::Message
  • Object
show all
Defined in:
lib/bbk/amqp/message.rb

Overview

Store information about consumed AMQP message

Instance Attribute Summary collapse

Instance Method Summary collapse

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

  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

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

#cloneObject



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

def clone
  self.class.new(consumer, delivery_info, properties, body)
end

#inspectObject

:nodoc:



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

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

#message_idObject



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

def message_id
  headers[:message_id]
end

#protocolObject



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

def protocol
  consumer&.protocols&.first
end

#reply_toObject



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

def reply_to
  headers[:reply_to] || user_id
end

#user_idObject



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

def user_id
  headers[:user_id]
end