amqp-utils 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.5.0
data/amqp-utils.gemspec CHANGED
@@ -5,17 +5,17 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amqp-utils}
8
- s.version = "0.4.3"
8
+ s.version = "0.5.0"
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{2011-08-05}
12
+ s.date = %q{2011-09-27}
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
16
16
  when needed.}
17
17
  s.email = %q{dougbarth@gmail.com}
18
- s.executables = ["amqp-peek", "amqp-deleteq", "amqp-dequeue", "amqp-unbind", "amqp-statq", "amqp-pop", "amqp-enqueue", "amqp-spy", "amqp-purge"]
18
+ s.executables = ["amqp-exchange", "amqp-delexch", "amqp-peek", "amqp-deleteq", "amqp-dequeue", "amqp-unbind", "amqp-statq", "amqp-pop", "amqp-enqueue", "amqp-spy", "amqp-purge"]
19
19
  s.extra_rdoc_files = [
20
20
  "README.txt"
21
21
  ]
@@ -28,8 +28,10 @@ Gem::Specification.new do |s|
28
28
  "VERSION",
29
29
  "amqp-utils.gemspec",
30
30
  "bin/amqp-deleteq",
31
+ "bin/amqp-delexch",
31
32
  "bin/amqp-dequeue",
32
33
  "bin/amqp-enqueue",
34
+ "bin/amqp-exchange",
33
35
  "bin/amqp-peek",
34
36
  "bin/amqp-pop",
35
37
  "bin/amqp-purge",
data/bin/amqp-delexch ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
+
5
+ class ExchnageDeleteCommand < AmqpUtils::Command
6
+
7
+ def prepare_options(options)
8
+ options.banner <<-BANNER.unindent
9
+ Deletes the supplied exchange.
10
+ WARNING: queue bindings might become obsolete!
11
+
12
+ #{command_name} exchange
13
+
14
+ BANNER
15
+ end
16
+
17
+ def validate
18
+ Trollop::die "need at least one exchange name" unless args[0] && !args[0].empty?
19
+ end
20
+
21
+ def execute
22
+ @exchanges = args
23
+ def @exchanges.delete_or_stop
24
+ exchange = pop
25
+ if exchange
26
+ conn = AMQP::Channel.new
27
+ exch = conn.__send__ :topic, exchange, {:passive => true}
28
+ puts "Deleting exchange #{exchange}"
29
+ puts "WARNING: Queues might be left unbound"
30
+ exch.delete
31
+ EM.next_tick { delete_or_stop }
32
+ else
33
+ AMQP.stop { EM.stop }
34
+ end
35
+ end
36
+
37
+ EM.next_tick { @exchanges.delete_or_stop }
38
+ end
39
+ end
40
+
41
+ ExchnageDeleteCommand.run
data/bin/amqp-exchange ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
+
5
+ class ExchangeDeclareCommand < AmqpUtils::Command
6
+ def prepare_options(options)
7
+ options.banner <<-BANNER.unindent
8
+ Declares a named exchange.
9
+
10
+ #{command_name} <type> <exchange>
11
+
12
+ BANNER
13
+ options.opt :durable, 'Makes the exchange survive across broker restarts',
14
+ :type => :boolean, :short => :none
15
+ options.opt :auto_delete, 'Makes the exchange auto_delete after no queues are using it',
16
+ :type => :boolean, :short => :none
17
+ options.opt :internal, 'Makes the exchange unusable by publishers. Used for exchange to exchange bindings',
18
+ :type => :boolean, :short => :none
19
+ options.opt :passive, 'Passively declares the exchange, which will cause an error if the exchange does not exist',
20
+ :type => :boolean, :short => :none
21
+ end
22
+
23
+ VALID_TYPES = %w(direct fanout topic)
24
+
25
+ def validate
26
+ @type, @exchange = args
27
+ Trollop::die "must supply both a type and name" unless @type
28
+ Trollop::die "must supply a name" unless @exchange
29
+ Trollop::die "type must be one of <#{VALID_TYPES.inspect}>" unless VALID_TYPES.include?(@type)
30
+ end
31
+
32
+ def execute
33
+ AMQP::Channel.error do |msg|
34
+ puts msg
35
+ EM.next_tick { AMQP.stop { EM.stop } }
36
+ end
37
+
38
+ exchange_options = {
39
+ :durable => options.durable,
40
+ :auto_delete => options.auto_delete,
41
+ :internal => options.internal,
42
+ :passive => options.passive,
43
+ :nowait => false
44
+ }
45
+ channel.__send__(@type, @exchange, exchange_options) do
46
+ EM.next_tick { AMQP.stop { EM.stop } }
47
+ end
48
+ end
49
+ end
50
+
51
+ ExchangeDeclareCommand.run
data/bin/amqp-peek CHANGED
@@ -21,6 +21,7 @@ class PeekCommand < AmqpUtils::Command
21
21
  :short => :none, :default => 'pretty'
22
22
  options.opt :quiet, 'Suppresses non-message content output',
23
23
  :short => 'q', :default => false
24
+ options.opt :num, 'Number of msgs to peek',:short => 'n', :default => 1
24
25
  end
25
26
 
26
27
  def validate
@@ -34,17 +35,19 @@ class PeekCommand < AmqpUtils::Command
34
35
  @queue = args[0]
35
36
 
36
37
  mq = MQ.new
37
- mq.queue(@queue, :passive => true).pop(:ack => true) do |header, message|
38
- if message
39
- puts "(#{@queue})" unless options[:quiet]
40
- deserialized_message = AmqpUtils::Serialization.deserialize(header.properties[:content_type], message)
41
- @formatter.generate(STDOUT, header, deserialized_message)
42
- else
43
- puts "(#{@queue}) empty"
38
+ queue = mq.queue(@queue, :passive => true)
39
+ options[:num].times do
40
+ queue.pop(:ack => true) do |header, message|
41
+ if message
42
+ puts "(#{@queue})" unless options[:quiet]
43
+ deserialized_message = AmqpUtils::Serialization.deserialize(header.properties[:content_type], message)
44
+ @formatter.generate(STDOUT, header, deserialized_message)
45
+ else
46
+ puts "(#{@queue}) empty"
47
+ end
44
48
  end
45
-
46
- AMQP.stop { EM.stop }
47
49
  end
50
+ AMQP.stop { EM.stop }
48
51
  end
49
52
  end
50
53
 
@@ -102,7 +102,8 @@ class AmqpUtils::Command
102
102
  @amqp ||= AMQP.start
103
103
  end
104
104
 
105
- def mq
106
- @mq ||= MQ.new
105
+ def channel
106
+ @channel ||= AMQP::Channel.new(@amqp)
107
107
  end
108
+ alias mq channel
108
109
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqp-utils
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Doug Barth
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-05 00:00:00 -05:00
18
+ date: 2011-09-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -135,6 +135,8 @@ description: |-
135
135
  when needed.
136
136
  email: dougbarth@gmail.com
137
137
  executables:
138
+ - amqp-exchange
139
+ - amqp-delexch
138
140
  - amqp-peek
139
141
  - amqp-deleteq
140
142
  - amqp-dequeue
@@ -157,8 +159,10 @@ files:
157
159
  - VERSION
158
160
  - amqp-utils.gemspec
159
161
  - bin/amqp-deleteq
162
+ - bin/amqp-delexch
160
163
  - bin/amqp-dequeue
161
164
  - bin/amqp-enqueue
165
+ - bin/amqp-exchange
162
166
  - bin/amqp-peek
163
167
  - bin/amqp-pop
164
168
  - bin/amqp-purge