Module: Bunnish::Command::Count

Defined in:
lib/bunnish/command/count.rb

Class Method Summary collapse

Class Method Details

.run(argv, input_stream = $stdin, output_stream = $stdout) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bunnish/command/count.rb', line 3

def self.run(argv, input_stream=$stdin, output_stream=$stdout)
  
  params = Bunnish.parse_opts(argv)
  
  host = params[:host]
  port = params[:port]
  user = params[:user]
  password = params[:password]
  durable = params[:durable]
  
  queue_name = argv.shift

  if queue_name.nil?
    Bunnish.logger.error("queue-name is not set")
    return 1
  end
  
  bunny = Bunny.new(:logging => false, :spec => '09', :host=>host, :port=>port, :user=>user, :pass=>password)
  
  # start a communication session with the amqp server
  bunny.start
  
  # create/get queue
  queue = bunny.queue(queue_name, :durable=>durable)
  
  # remain_count = queue.status[:message_count]
    
  output_stream.puts queue.status[:message_count]
  
  # Close client
  bunny.stop
  
end