Module: Vx::Common::AMQP::Consumer::Publish

Included in:
ClassMethods
Defined in:
lib/vx/common/amqp/consumer/publish.rb

Instance Method Summary collapse

Instance Method Details

#publish(message, options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vx/common/amqp/consumer/publish.rb', line 6

def publish(message, options = nil)
  session.open

  options ||= {}
  options[:routing_key]  = routing_key if routing_key && !options.key?(:routing_key)
  options[:headers]      = headers     if headers && !options.key?(:headers)
  options[:content_type] ||= content_type || config.content_type

  x = declare_exchange

  instrumentation = {
    message:  message.inspect,
    exchange: x.name,
    consumer: consumer_id
  }

  instrument("start_publishing.consumer.amqp", instrumentation)
  instrument("process_publishing.consumer.amqp", instrumentation) do
    m = serialize_message message, options[:content_type]
    x.publish m, options
  end

  self
end

#serialize_message(message, content_type) ⇒ Object



31
32
33
# File 'lib/vx/common/amqp/consumer/publish.rb', line 31

def serialize_message(message, content_type)
  Common::AMQP::Formatter.pack(content_type, message)
end