amqp-utils 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
data/amqp-utils.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amqp-utils}
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Doug Barth"]
12
- s.date = %q{2010-09-28}
12
+ s.date = %q{2010-09-30}
13
13
  s.description = %q{Command line utilies for interacting with AMQP compliant queues.
14
14
  The intention is provide simple management tools that can be used to complete ad hoc
15
15
  housework on an AMQP queue. In addition, simple scripts can be layered over the tools
data/bin/amqp-deleteq CHANGED
@@ -12,7 +12,7 @@ class QueueDeleteCommand < AmqpUtils::Command
12
12
  end
13
13
 
14
14
  def validate
15
- raise "need at least one queue name" unless args[0] && !args[0].empty?
15
+ Trollop::die "need at least one queue name" unless args[0] && !args[0].empty?
16
16
  end
17
17
 
18
18
  def execute
@@ -21,7 +21,7 @@ class QueueDeleteCommand < AmqpUtils::Command
21
21
  queue = pop
22
22
  if queue
23
23
  puts "Deleting #{queue}..."
24
- MQ.new.queue(queue).delete
24
+ MQ.new.queue(queue, :passive => true).delete
25
25
  EM.next_tick { delete_or_stop }
26
26
  else
27
27
  AMQP.stop { EM.stop }
data/bin/amqp-dequeue CHANGED
@@ -19,12 +19,14 @@ class DequeueCommand < AmqpUtils::Command
19
19
  end
20
20
 
21
21
  def validate
22
- raise "need at least one queue name" if args.empty?
22
+ Trollop::die "need at least one queue name" if args.empty?
23
+
24
+ @formatter = AmqpUtils::MessageFormatter.for_type(options[:format])
25
+ Trollop::die :format, "not an available type: #{AmqpUtils::MessageFormatter.types.join(", ")}" unless @formatter
23
26
  end
24
27
 
25
28
  def execute
26
29
  @queues = args
27
- @formatter = AmqpUtils::MessageFormatter.for_type(options[:format])
28
30
 
29
31
  @queues.each do |queue|
30
32
  puts "Dequeueing from #{queue} (^C to stop)..." unless options[:quiet]
@@ -34,7 +36,7 @@ class DequeueCommand < AmqpUtils::Command
34
36
  puts "(#{queue})" unless options[:quiet]
35
37
  @formatter.generate(STDOUT, header, message)
36
38
  end
37
- mq.queue(queue).subscribe(&process_message)
39
+ mq.queue(queue, :passive => true).subscribe(&process_message)
38
40
  end
39
41
  end
40
42
  end
data/bin/amqp-enqueue CHANGED
@@ -25,7 +25,7 @@ class EnqueueCommand < AmqpUtils::Command
25
25
  h.split('=')
26
26
  end.flatten)]
27
27
  end
28
- raise "need a queue to publish to" unless args[0] && !args[0].empty?
28
+ Trollop::die "need a queue to publish to" unless args[0] && !args[0].empty?
29
29
  end
30
30
 
31
31
  def execute
data/bin/amqp-peek CHANGED
@@ -21,15 +21,17 @@ class PeekCommand < AmqpUtils::Command
21
21
  end
22
22
 
23
23
  def validate
24
- raise "need a queue name" unless args[0] && !args[0].empty?
24
+ Trollop::die "need a queue name" unless args[0] && !args[0].empty?
25
+
26
+ @formatter = AmqpUtils::MessageFormatter.for_type(options[:format])
27
+ Trollop::die :format, "not an available type: #{AmqpUtils::MessageFormatter.types.join(", ")}" unless @formatter
25
28
  end
26
29
 
27
30
  def execute
28
31
  @queue = args[0]
29
- @formatter = AmqpUtils::MessageFormatter.for_type(options[:format])
30
32
 
31
33
  mq = MQ.new
32
- mq.queue(@queue).pop(:ack => true) do |header, message|
34
+ mq.queue(@queue, :passive => true).pop(:ack => true) do |header, message|
33
35
  if message
34
36
  puts "(#{@queue})"
35
37
  @formatter.generate(STDOUT, header, message)
data/bin/amqp-pop CHANGED
@@ -17,15 +17,17 @@ class PopCommand < AmqpUtils::Command
17
17
  end
18
18
 
19
19
  def validate
20
- raise "need a queue name" unless args[0] && !args[0].empty?
20
+ Trollop::die "need a queue name" unless args[0] && !args[0].empty?
21
+
22
+ @formatter = AmqpUtils::MessageFormatter.for_type(options[:format])
23
+ Trollop::die :format, "not an available type: #{AmqpUtils::MessageFormatter.types.join(", ")}" unless @formatter
21
24
  end
22
25
 
23
26
  def execute
24
27
  @queue = args[0]
25
- @formatter = AmqpUtils::MessageFormatter.for_type(options[:format])
26
28
 
27
29
  mq = MQ.new
28
- mq.queue(@queue).pop do |header, message|
30
+ mq.queue(@queue, :passive => true).pop do |header, message|
29
31
  if message
30
32
  puts "(#{@queue})"
31
33
  @formatter.generate(STDOUT, header, message)
data/bin/amqp-purge CHANGED
@@ -12,7 +12,7 @@ class PurgeCommand < AmqpUtils::Command
12
12
  end
13
13
 
14
14
  def validate
15
- raise "need at least one queue name" if args.empty?
15
+ Trollop::die "need at least one queue name" if args.empty?
16
16
  end
17
17
 
18
18
  def execute
data/bin/amqp-statq CHANGED
@@ -12,7 +12,7 @@ class QueueStatCommand < AmqpUtils::Command
12
12
  end
13
13
 
14
14
  def validate
15
- raise "need at least one queue name" unless args[0] && !args[0].empty?
15
+ Trollop::die "need at least one queue name" unless args[0] && !args[0].empty?
16
16
  end
17
17
 
18
18
  def execute
@@ -7,14 +7,15 @@ class AmqpUtils::Command
7
7
  def run(args = ARGV)
8
8
  command = new(args)
9
9
  command.process_options
10
+ command.validate
10
11
 
11
12
  begin
12
- command.validate
13
- rescue RuntimeError => e
14
- Trollop::die(e.message)
13
+ command.go
14
+ rescue => e
15
+ STDERR.puts e.message
16
+ STDERR.puts e.backtrace.join("\n") if command.options.verbose
17
+ exit 1
15
18
  end
16
-
17
- command.go
18
19
  end
19
20
  end
20
21
 
@@ -54,10 +55,10 @@ class AmqpUtils::Command
54
55
  end
55
56
 
56
57
  # Called to validate that the supplied command line options and arguments
57
- # are valid. If there is a problem with the supplied values, and exception
58
- # should be raised.
58
+ # are valid. If there is a problem with the supplied values, Trollop::die
59
+ # should be called.
59
60
  #
60
- # Subclasses show override this method and do their validation.
61
+ # Subclasses should override this method and do their validation.
61
62
  def validate
62
63
  end
63
64
 
@@ -3,7 +3,12 @@ class AmqpUtils::MessageFormatter
3
3
  @@formatters ||= {}
4
4
 
5
5
  def for_type(format_type)
6
- @@formatters[format_type.downcase].new
6
+ klass = @@formatters[format_type.downcase]
7
+ klass && klass.new
8
+ end
9
+
10
+ def types
11
+ @@formatters.keys
7
12
  end
8
13
 
9
14
  def register_formatter(formatter, format_type)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 2
9
- version: 0.2.2
8
+ - 3
9
+ version: 0.2.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Doug Barth
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-28 00:00:00 -05:00
17
+ date: 2010-09-30 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency