Module: Bunnish::Core::Publish

Defined in:
lib/bunnish/core/publish.rb

Class Method Summary collapse

Class Method Details

.create_direct_exchange(bunny, queue_name, log_streams = {}, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bunnish/core/publish.rb', line 34

def self.create_direct_exchange(bunny, queue_name, log_streams={}, options={})
  durable = options[:durable]
  log_label = options[:log_label]

  Bunnish.logger.info "#{log_label} create direct exchange '#{queue_name}'"
  direct_exchange = bunny.exchange(queue_name, :type=>:direct)

  Bunnish.logger.info "#{log_label} create queue '#{queue_name}'"
  queue = bunny.queue(queue_name, :durable=>durable)

  Bunnish.logger.info "#{log_label} bind queue '#{queue_name}' to direct exchange '#{queue_name}'"
  queue.bind(direct_exchange)

  return direct_exchange
end

.create_fanout_exchange(bunny, queue_name_list, log_streams = {}, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bunnish/core/publish.rb', line 16

def self.create_fanout_exchange(bunny, queue_name_list, log_streams={}, options={})
  durable = options[:durable]
  log_label = options[:log_label]
  exchange_name = options[:exchange_name]
  
  Bunnish.logger.info "#{log_label} create fanout exchange '#{exchange_name}'"
  fanout_exchange = bunny.exchange(exchange_name, :type=>:fanout, :persistent=>durable)
  
  queue_name_list.each do |queue_name|
  # create/get queue
    Bunnish.logger.info "#{log_label} create queue '#{queue_name}'"
    queue = bunny.queue(queue_name, :durable=>durable)
    Bunnish.logger.info "#{log_label} bind queue '#{queue_name}' to fanout exchange '#{exchange_name}'"
    queue.bind(fanout_exchange)
  end
  return fanout_exchange
end

.output_publish_log(streams, queue, count, log_label) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/bunnish/core/publish.rb', line 3

def self.output_publish_log(streams, queue, count, log_label)
  message_count = '?'
  consumer_count = '?'
  begin
    message_count = queue.status[:message_count]
    consumer_count = queue.status[:consumer_count]
  rescue Exception=>e
  end
  
  message = "#{log_label} published #{count} messages into #{queue.name}(#{message_count} messages, #{consumer_count} consumers)"
  Bunnish::Core::Common.output_log(streams, "INFO", message)
end