Class: BmcDaemonLib::MqConsumer

Inherits:
MqEndpoint show all
Includes:
LoggerHelper
Defined in:
lib/bmc-daemon-lib/mq_consumer.rb

Instance Attribute Summary

Attributes included from LoggerHelper

#logger

Instance Method Summary collapse

Instance Method Details

#listen_to(topic, rkey) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bmc-daemon-lib/mq_consumer.rb', line 23

def listen_to topic, rkey
  # puts "listen_to(#{topic},#{rkey})"
  log_info "listen_to [#{topic}] [#{rkey}] > [#{@queue.name}]"
  @queue.bind topic, routing_key: rkey

  # Handle errors
  rescue Bunny::NotFound => e
    log_error "exchange not found: #{e.inspect}"
    raise MqConsumerTopicNotFound, e.message

  rescue StandardError => e
    log_error "UNEXPECTED EXCEPTION: #{e.inspect}"
    raise MqConsumerException, e.message
end

#subscribe_to_queue(name, context = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bmc-daemon-lib/mq_consumer.rb', line 11

def subscribe_to_queue name, context = nil
  log_info "subscribe_to_queue [#{name}]"

  # Queue for this rule
  @queue = @channel.queue(name, auto_delete: false, durable: true)

  # Create consumer on this queue
  @queue.subscribe(manual_ack: AMQP_MANUAL_ACK, on_cancellation: :consumer_cancelled) do |delivery_info, , payload|
    handle_receive context, delivery_info, , payload
  end
end