Class: Istox::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/istox/helpers/subscriber.rb

Overview

Publisher is relying on BunnyBoot to publish message, please make sure BunnyBoot is initalised properly first during runtime.

Class Method Summary collapse

Class Method Details

.get_channelsObject



34
35
36
# File 'lib/istox/helpers/subscriber.rb', line 34

def get_channels
  @chs
end

.start_subscribe(subscribing_consumer_keys = []) ⇒ Object

optionally can pass in consumer_key for single subscription / consumer_keys for multiple subcriptions consumer_key must be defined in amqp.yml if nothing pass in it will auto subscribe to all available consumers defined in amqp.yml queues key



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/istox/helpers/subscriber.rb', line 11

def start_subscribe(subscribing_consumer_keys = [])
  unless @flag
    @mutex = Mutex.new unless @mutex.present?
    @mutex.synchronize do
      unless @flag
        # Create connection
        @conn = ::Istox::BunnyBoot.connection
        @flag = true
      end
    end
  end

  subscribing_consumer_keys = ::Istox::BunnyBoot.queues_keys_for_subscribe if subscribing_consumer_keys.empty?
  subscribing_consumer_keys.each do |key|
    log.debug "Do subscribe key #{key}"
    if key.is_a?(String)
      do_subscribe key.to_s
    elsif key.is_a?(Hash)
      do_subscribe key[:id], key[:multiple], key[:block]
    end
  end
end