Class: BugsBunny::Rabbit

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/bugs_bunny/rabbit.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#print_queue, #print_table, #read_dump

Constructor Details

#initialize(params = nil) ⇒ Rabbit

Returns a new instance of Rabbit.



7
8
# File 'lib/bugs_bunny/rabbit.rb', line 7

def initialize(params=nil)
end

Class Method Details

.halt(msg = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/bugs_bunny/rabbit.rb', line 73

def self.halt(msg=nil)
  puts msg if msg
  MQ.queues{ |q| q.unsubscribe }
  AMQP.stop { EM.stop }
  #EM.stop_event_loop
  #exit
end

Instance Method Details

#bindingsObject Also known as: binds, bi



57
58
59
60
61
62
63
64
65
# File 'lib/bugs_bunny/rabbit.rb', line 57

def bindings
  arr = `rabbitmqctl list_bindings -p #{Opt[:rabbit][:vhost]}`.split("\n")
  arr.map { |l|l.gsub(/^\t/, "") }.sort.each do |l|
    next if l =~ /Listing|\.\.\./
    from, to, args = l.split("\t")
    puts "#{from} <=> #{to}"
  end
  halt
end

#exchangesObject Also known as: ex



47
48
49
50
51
52
53
54
# File 'lib/bugs_bunny/rabbit.rb', line 47

def exchanges
  arr = `rabbitmqctl list_exchanges -p #{Opt[:rabbit][:vhost]} name type durable auto_delete arguments`.split("\n").map do |e|
    BugsBunny::Exchange.parse(e)
  end.reject(&:nil?).sort

  print_table "Exchanges", arr, :name, :kind, :durable_x, :delete_x
  halt
end

#halt(msg = nil) ⇒ Object



69
70
71
# File 'lib/bugs_bunny/rabbit.rb', line 69

def halt(msg=nil)
  BugsBunny::Rabbit.halt(msg)
end

#queue(q, action = "info", *params) ⇒ Object Also known as: q



36
37
38
39
40
41
42
43
44
# File 'lib/bugs_bunny/rabbit.rb', line 36

def queue(q, action="info", *params)
  rec = BugsBunny::Queue.new(q)
  if rec.respond_to?(action)
    rec.send(action, *params)
  else
    puts "No such action for queues."
    halt
  end
end

#queues(param = nil, name = nil) ⇒ Object Also known as: qu



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bugs_bunny/rabbit.rb', line 19

def queues(param=nil,name=nil)
  if param == "new"
    return halt("new <name>") unless name
    BugsBunny::Queue.create(name)
    return halt
  end
  qs = BugsBunny::Queue.all
  unless param
    print_table "Queues", qs.sort, :msgs, :name_kind,
      :users, :ready, :noack, :commit, :acts, :memory
  else
    qs.each(&:"#{param}")
  end
  halt
end

#start!(command) ⇒ Object



10
11
12
13
# File 'lib/bugs_bunny/rabbit.rb', line 10

def start!(command)
 # @mq = MQ.new AMQP::connect
  send(*command)
end

#vhostsObject



15
16
17
# File 'lib/bugs_bunny/rabbit.rb', line 15

def vhosts
  puts `rabbitmqctl list_vhosts`
end