amqp-utils 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -16,11 +16,12 @@ begin
16
16
  gem.rubyforge_project = "amqp-utils"
17
17
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
18
 
19
- gem.add_dependency('amqp', '~> 0.6.7')
20
- gem.add_dependency('trollop', '~> 1.10.2')
19
+ gem.add_dependency('amqp', '~> 0.7.1')
20
+ gem.add_dependency('trollop', '~> 1.16.2')
21
21
  gem.add_dependency('facets', '~> 2.7.0')
22
22
  gem.add_dependency('clio', '~> 0.3.0')
23
23
  gem.add_dependency('json', '~> 1.1.6')
24
+ gem.add_dependency('heredoc_unindent', '~> 1.1.2')
24
25
  end
25
26
  Jeweler::GemcutterTasks.new
26
27
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/amqp-utils.gemspec CHANGED
@@ -1,81 +1,79 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amqp-utils}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.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-02-02}
12
+ s.date = %q{2011-06-20}
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-deleteq", "amqp-dequeue", "amqp-enqueue", "amqp-peek", "amqp-pop", "amqp-purge", "amqp-spy", "amqp-statq"]
18
+ s.executables = ["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
  ]
22
22
  s.files = [
23
- ".gitignore",
24
- "History.txt",
25
- "License.txt",
26
- "README.txt",
27
- "Rakefile",
28
- "TODO.txt",
29
- "VERSION",
30
- "amqp-utils.gemspec",
31
- "bin/amqp-deleteq",
32
- "bin/amqp-dequeue",
33
- "bin/amqp-enqueue",
34
- "bin/amqp-peek",
35
- "bin/amqp-pop",
36
- "bin/amqp-purge",
37
- "bin/amqp-spy",
38
- "bin/amqp-statq",
39
- "lib/amqp_utils.rb",
40
- "lib/amqp_utils/command.rb",
41
- "lib/amqp_utils/message_formatter.rb",
42
- "test/test_amqp_utils.rb",
43
- "test/test_helper.rb"
23
+ "History.txt",
24
+ "License.txt",
25
+ "README.txt",
26
+ "Rakefile",
27
+ "TODO.txt",
28
+ "VERSION",
29
+ "amqp-utils.gemspec",
30
+ "bin/amqp-deleteq",
31
+ "bin/amqp-dequeue",
32
+ "bin/amqp-enqueue",
33
+ "bin/amqp-peek",
34
+ "bin/amqp-pop",
35
+ "bin/amqp-purge",
36
+ "bin/amqp-spy",
37
+ "bin/amqp-statq",
38
+ "bin/amqp-unbind",
39
+ "lib/amqp_utils.rb",
40
+ "lib/amqp_utils/command.rb",
41
+ "lib/amqp_utils/message_formatter.rb",
42
+ "lib/amqp_utils/serialization.rb",
43
+ "test/test_amqp_utils.rb",
44
+ "test/test_helper.rb"
44
45
  ]
45
46
  s.homepage = %q{http://github.com/dougbarth/amqp-utils}
46
- s.rdoc_options = ["--charset=UTF-8"]
47
47
  s.require_paths = ["lib"]
48
48
  s.rubyforge_project = %q{amqp-utils}
49
- s.rubygems_version = %q{1.3.7}
49
+ s.rubygems_version = %q{1.4.2}
50
50
  s.summary = %q{Command line utilities for interacting with AMQP compliant queues}
51
- s.test_files = [
52
- "test/test_amqp_utils.rb",
53
- "test/test_helper.rb"
54
- ]
55
51
 
56
52
  if s.respond_to? :specification_version then
57
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
53
  s.specification_version = 3
59
54
 
60
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
- s.add_runtime_dependency(%q<amqp>, ["~> 0.6.7"])
62
- s.add_runtime_dependency(%q<trollop>, ["~> 1.10.2"])
56
+ s.add_runtime_dependency(%q<amqp>, ["~> 0.7.1"])
57
+ s.add_runtime_dependency(%q<trollop>, ["~> 1.16.2"])
63
58
  s.add_runtime_dependency(%q<facets>, ["~> 2.7.0"])
64
59
  s.add_runtime_dependency(%q<clio>, ["~> 0.3.0"])
65
60
  s.add_runtime_dependency(%q<json>, ["~> 1.1.6"])
61
+ s.add_runtime_dependency(%q<heredoc_unindent>, ["~> 1.1.2"])
66
62
  else
67
- s.add_dependency(%q<amqp>, ["~> 0.6.7"])
68
- s.add_dependency(%q<trollop>, ["~> 1.10.2"])
63
+ s.add_dependency(%q<amqp>, ["~> 0.7.1"])
64
+ s.add_dependency(%q<trollop>, ["~> 1.16.2"])
69
65
  s.add_dependency(%q<facets>, ["~> 2.7.0"])
70
66
  s.add_dependency(%q<clio>, ["~> 0.3.0"])
71
67
  s.add_dependency(%q<json>, ["~> 1.1.6"])
68
+ s.add_dependency(%q<heredoc_unindent>, ["~> 1.1.2"])
72
69
  end
73
70
  else
74
- s.add_dependency(%q<amqp>, ["~> 0.6.7"])
75
- s.add_dependency(%q<trollop>, ["~> 1.10.2"])
71
+ s.add_dependency(%q<amqp>, ["~> 0.7.1"])
72
+ s.add_dependency(%q<trollop>, ["~> 1.16.2"])
76
73
  s.add_dependency(%q<facets>, ["~> 2.7.0"])
77
74
  s.add_dependency(%q<clio>, ["~> 0.3.0"])
78
75
  s.add_dependency(%q<json>, ["~> 1.1.6"])
76
+ s.add_dependency(%q<heredoc_unindent>, ["~> 1.1.2"])
79
77
  end
80
78
  end
81
79
 
data/bin/amqp-deleteq CHANGED
@@ -4,11 +4,11 @@ require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
4
 
5
5
  class QueueDeleteCommand < AmqpUtils::Command
6
6
  def prepare_options(options)
7
- options.banner %Q{
8
- |Deletes the supplied queues.
9
- |
10
- | #{command_name} <queue> [<another queue> ...]
11
- }.margin
7
+ options.banner <<-BANNER.unindent
8
+ Deletes the supplied queues.
9
+
10
+ #{command_name} <queue> [<another queue> ...]
11
+ BANNER
12
12
  end
13
13
 
14
14
  def validate
data/bin/amqp-dequeue CHANGED
@@ -2,16 +2,17 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
4
  require File.dirname(__FILE__) + '/../lib/amqp_utils/message_formatter'
5
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/serialization'
5
6
 
6
7
  class DequeueCommand < AmqpUtils::Command
7
8
  def prepare_options(options)
8
- options.banner %Q{
9
- |Removes messages from the supplied queues and displays them on STDOUT.
10
- |
11
- | #{command_name} <queue> [<another queue> ...]
12
- |
13
- |Dequeue options:
14
- }.margin
9
+ options.banner <<-BANNER.unindent
10
+ Removes messages from the supplied queues and displays them on STDOUT.
11
+
12
+ #{command_name} <queue> [<another queue> ...]
13
+
14
+ Dequeue options:
15
+ BANNER
15
16
  options.opt :format, 'The format that the messages should be displayed as',
16
17
  :short => :none, :default => 'pretty'
17
18
  options.opt :quiet, 'Suppresses non-message content output',
@@ -34,7 +35,8 @@ class DequeueCommand < AmqpUtils::Command
34
35
 
35
36
  process_message = lambda do |header, message|
36
37
  puts "(#{queue})" unless options[:quiet]
37
- @formatter.generate(STDOUT, header, message)
38
+ deserialized_message = AmqpUtils::Serialization.deserialize(header.properties[:content_type], message)
39
+ @formatter.generate(STDOUT, header, deserialized_message)
38
40
  end
39
41
  mq.queue(queue, :passive => true).subscribe(&process_message)
40
42
  end
data/bin/amqp-enqueue CHANGED
@@ -1,22 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/message_formatter'
5
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/serialization'
4
6
  require 'clio/progressbar'
7
+ require 'stringio'
5
8
 
6
9
  class EnqueueCommand < AmqpUtils::Command
7
10
  def prepare_options(options)
8
- options.banner %Q{
9
- |Publishes a message to a particular queue.
10
- |
11
- | #{command_name} <queue>
12
- |
13
- |Enqueue options:
14
- }.margin
11
+ options.banner <<-BANNER.unindent
12
+ Publishes a message or a series of messages to a particular queue.
13
+
14
+ #{command_name} <queue>
15
+
16
+ When publishing a series of messages, the messages should be separated by a
17
+ newline, with one message per line.
18
+
19
+ Enqueue options:
20
+ BANNER
21
+ options.opt :content_type, 'Sets the content_type header and chooses an appropriate serializer', :type => :string, :short => :none
15
22
  options.opt :persistent, 'Mark messages as persistent.', :short => :none
16
23
  options.opt :priority, 'The priority of this message', :type => :int, :short => :none, :default => 1
17
- options.opt :count, 'Number of times the message should be published.', :type => :int, :default => 1
24
+ options.opt :count, 'Number of times the message should be published. If multiple messages are provided, only the first message is published multiple times.', :type => :int, :default => 1
18
25
  options.opt :header, 'A key-value pair to be set in "headers" field of the AMQP header', :short => :none, :type => :string, :multi => true
19
26
  options.opt :message, 'The message to publish to the queue. Comes from STDIN if not provided.', :type => :string, :default => nil
27
+ options.opt :format, 'The format that the message is supplied in.', :short => :none, :default => 'message'
20
28
  end
21
29
 
22
30
  def validate
@@ -26,30 +34,82 @@ class EnqueueCommand < AmqpUtils::Command
26
34
  end.flatten)]
27
35
  end
28
36
  Trollop::die "need a queue to publish to" unless args[0] && !args[0].empty?
37
+
38
+ @formatter = AmqpUtils::MessageFormatter.for_type(options[:format])
39
+ Trollop::die :format, "not an available type: #{AmqpUtils::MessageFormatter.types.join(", ")}" unless @formatter
29
40
  end
30
41
 
31
42
  def execute
32
43
  @queue = args
33
- @message = options[:message] || STDIN.read
44
+ if options[:message]
45
+ @message_io = StringIO.new(options[:message])
46
+ else
47
+ @message_io = STDIN
48
+ end
49
+
50
+ if options[:count] > 1
51
+ publisher = EM.spawn do |queue, message, messages, options|
52
+ @progress ||= Clio::Progressbar.new('Enqueuing', options[:count]) if options[:count] > 1
53
+
54
+ if messages > 0
55
+ @mq ||= MQ.new
34
56
 
35
- publisher = EM.spawn do |queue, message, messages, options|
36
- @progress ||= Clio::Progressbar.new('Enqueuing', options[:count])
57
+ publish_options = {
58
+ :persistent => options.persistent,
59
+ :headers => options[:header],
60
+ :priority => options.priority,
61
+ :content_type => options.content_type
62
+ }
63
+
64
+ serialized_message = AmqpUtils::Serialization.serialize(options.content_type, message)
65
+
66
+ @mq.queue(queue, :durable => true, :auto_delete => false).
67
+ publish(serialized_message, publish_options)
68
+
69
+ @progress.inc if @progress
70
+ publisher.notify(queue, message, messages - 1, options)
71
+ else
72
+ @progress.finish if @progress
73
+ EM.next_tick { AMQP.stop { EM.stop } }
74
+ end
75
+ end
37
76
 
38
- if messages > 0
77
+ message = @formatter.load(@message_io)
78
+ publisher.notify(@queue, message, options[:count], options)
79
+ else
80
+ publisher = EM.spawn do |queue, message_io, formatter, options|
39
81
  @mq ||= MQ.new
40
- headers = options[:header]
41
- @mq.queue(queue, :durable => true, :auto_delete => false).
42
- publish(message, :persistent => options.persistent, :headers => headers, :priority => options.priority)
43
-
44
- @progress.inc
45
- publisher.notify(queue, message, messages - 1, options)
46
- else
47
- @progress.finish
48
- EM.next_tick { AMQP.stop { EM.stop } }
82
+
83
+ message = formatter.load(message_io)
84
+ if message
85
+ raise "expected a value for message in #{message.inspect}" unless message['message']
86
+
87
+ publish_options = {
88
+ :app_id => 'amqp-utils',
89
+ :persistent => options.persistent,
90
+ :headers => options[:header],
91
+ :priority => options.priority,
92
+ :content_type => options.content_type
93
+ }
94
+ if header = message['header']
95
+ publish_options[:message_id] = header['message_id']
96
+ publish_options[:priority] = header['priority'] unless options.priority_given
97
+ publish_options[:expiration] = header['expiration']
98
+ end
99
+
100
+ serialized_message = AmqpUtils::Serialization.serialize(options.content_type, message['message'])
101
+
102
+ @mq.queue(queue, :durable => true, :auto_delete => false).
103
+ publish(serialized_message, publish_options)
104
+
105
+ publisher.notify(queue, message_io, formatter, options)
106
+ else
107
+ EM.next_tick { AMQP.stop { EM.stop } }
108
+ end
49
109
  end
50
- end
51
110
 
52
- publisher.notify(@queue, @message, options[:count], options)
111
+ publisher.notify(@queue, @message_io, @formatter, options)
112
+ end
53
113
  end
54
114
  end
55
115
 
data/bin/amqp-peek CHANGED
@@ -2,22 +2,25 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
4
  require File.dirname(__FILE__) + '/../lib/amqp_utils/message_formatter'
5
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/serialization'
5
6
 
6
7
  class PeekCommand < AmqpUtils::Command
7
8
  def prepare_options(options)
8
- options.banner %Q{
9
- |Displays the head of the queue without removing the message from the queue.
10
- |
11
- | #{command_name} <queue>
12
- |
13
- | NOTE: This operation does have side effects on the server. The message is
14
- | placed at the end of the queue after returning from this method. The
15
- | message is also marked as being redelivered.
16
- |
17
- |Peek options:
18
- }.margin
9
+ options.banner <<-BANNER.unindent
10
+ Displays the head of the queue without removing the message from the queue.
11
+
12
+ #{command_name} <queue>
13
+
14
+ NOTE: This operation does have side effects on the server. The message is
15
+ placed at the end of the queue after returning from this method. The
16
+ message is also marked as being redelivered.
17
+
18
+ Peek options:
19
+ BANNER
19
20
  options.opt :format, 'The format that the messages should be displayed as',
20
21
  :short => :none, :default => 'pretty'
22
+ options.opt :quiet, 'Suppresses non-message content output',
23
+ :short => 'q', :default => false
21
24
  end
22
25
 
23
26
  def validate
@@ -33,8 +36,9 @@ class PeekCommand < AmqpUtils::Command
33
36
  mq = MQ.new
34
37
  mq.queue(@queue, :passive => true).pop(:ack => true) do |header, message|
35
38
  if message
36
- puts "(#{@queue})"
37
- @formatter.generate(STDOUT, header, 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)
38
42
  else
39
43
  puts "(#{@queue}) empty"
40
44
  end
data/bin/amqp-pop CHANGED
@@ -2,18 +2,21 @@
2
2
 
3
3
  require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
4
  require File.dirname(__FILE__) + '/../lib/amqp_utils/message_formatter'
5
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/serialization'
5
6
 
6
7
  class PopCommand < AmqpUtils::Command
7
8
  def prepare_options(options)
8
- options.banner %Q{
9
- |Pops a single message from the queue.
10
- |
11
- | #{command_name} <queue>
12
- |
13
- |Pop options:
14
- }.margin
9
+ options.banner <<-BANNER.unindent
10
+ Pops a single message from the queue.
11
+
12
+ #{command_name} <queue>
13
+
14
+ Pop options:
15
+ BANNER
15
16
  options.opt :format, 'The format that the messages should be displayed as',
16
17
  :short => :none, :default => 'pretty'
18
+ options.opt :quiet, 'Suppresses non-message content output',
19
+ :short => 'q', :default => false
17
20
  end
18
21
 
19
22
  def validate
@@ -29,8 +32,9 @@ class PopCommand < AmqpUtils::Command
29
32
  mq = MQ.new
30
33
  mq.queue(@queue, :passive => true).pop do |header, message|
31
34
  if message
32
- puts "(#{@queue})"
33
- @formatter.generate(STDOUT, header, message)
35
+ puts "(#{@queue})" unless options[:quiet]
36
+ deserialized_message = AmqpUtils::Serialization.deserialize(header.properties[:content_type], message)
37
+ @formatter.generate(STDOUT, header, deserialized_message)
34
38
  else
35
39
  puts "(#{@queue}) empty"
36
40
  end
data/bin/amqp-purge CHANGED
@@ -4,11 +4,11 @@ require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
4
 
5
5
  class PurgeCommand < AmqpUtils::Command
6
6
  def prepare_options(options)
7
- options.banner %Q{
8
- |Removes all messages from the supplied queues.
9
- |
10
- | #{command_name} <queue> [<another queue> ...]
11
- }.margin
7
+ options.banner <<-BANNER.unindent
8
+ Removes all messages from the supplied queues.
9
+
10
+ #{command_name} <queue> [<another queue> ...]
11
+ BANNER
12
12
  end
13
13
 
14
14
  def validate
data/bin/amqp-spy CHANGED
@@ -5,13 +5,13 @@ require File.dirname(__FILE__) + '/../lib/amqp_utils/message_formatter'
5
5
 
6
6
  class SpyCommand < AmqpUtils::Command
7
7
  def prepare_options(options)
8
- options.banner %Q{
9
- |Spies on a specific exchange and routing key.
10
- |
11
- | #{command_name} <exchange> [<routing_key>]
12
- |
13
- |Spy options:
14
- }.margin
8
+ options.banner <<-BANNER.unindent
9
+ Spies on a specific exchange and routing key.
10
+
11
+ #{command_name} <exchange> [<routing_key>]
12
+
13
+ Spy options:
14
+ BANNER
15
15
  options.opt :format, 'The format that the messages should be displayed as',
16
16
  :short => :none, :default => 'pretty'
17
17
  end
@@ -27,10 +27,10 @@ class SpyCommand < AmqpUtils::Command
27
27
  @exchange_name = args[0]
28
28
  @routing_key = args[1] || '*'
29
29
  spy_queue = "amqp-spy.#{@routing_key}." + (0...6).map{ (('a'..'f').to_a + (0..9).to_a)[rand(16)] }.join
30
-
30
+
31
31
  queue = mq.queue(spy_queue, :auto_delete => true)
32
32
  queue.bind(@exchange_name, :routing_key => @routing_key)
33
-
33
+
34
34
  queue.subscribe do |header, message|
35
35
  @formatter.generate(STDOUT, header, message)
36
36
  end
data/bin/amqp-statq CHANGED
@@ -4,11 +4,11 @@ require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
4
 
5
5
  class QueueStatCommand < AmqpUtils::Command
6
6
  def prepare_options(options)
7
- options.banner %Q{
8
- |Gets statistics on the queues specified.
9
- |
10
- | #{command_name} <queue> [<another_queue> ...]
11
- }.margin
7
+ options.banner <<-BANNER.unindent
8
+ Gets statistics on the queues specified.
9
+
10
+ #{command_name} <queue> [<another_queue> ...]
11
+ BANNER
12
12
  end
13
13
 
14
14
  def validate
data/bin/amqp-unbind ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/command'
4
+ require File.dirname(__FILE__) + '/../lib/amqp_utils/message_formatter'
5
+
6
+ class UnbindCommand < AmqpUtils::Command
7
+ def prepare_options(options)
8
+ options.banner <<-BANNER.unindent
9
+ Unbind a specific queue from a exchange with routing key.
10
+
11
+ #{command_name} <queue> <exchange> [<routing_key>]
12
+ BANNER
13
+ end
14
+
15
+ def validate
16
+ Trollop::die "need a queue and an exchange names to unbind" if args.size < 2
17
+ end
18
+
19
+ def execute
20
+ @queue_name = args[0]
21
+ @exchange_name = args[1]
22
+ @routing_key = args[2]
23
+
24
+ puts "Unbinding queue '#{@queue_name}' from exchange '#{@exchange_name}' with routing key '#{@routing_key}'..."
25
+
26
+ mq.queue(@queue_name, :passive => true).unbind(@exchange_name, :routing_key => @routing_key)
27
+
28
+ AMQP.stop { EM.stop }
29
+ end
30
+ end
31
+
32
+ UnbindCommand.run
@@ -35,10 +35,10 @@ class AmqpUtils::Command
35
35
  version(command.version)
36
36
  command.prepare_options(self) if command.respond_to?(:prepare_options)
37
37
 
38
- banner %Q{
39
- |
40
- |Standard options:
41
- }.margin
38
+ banner <<-END.unindent
39
+
40
+ Standard options:
41
+ END
42
42
  opt :host, 'The AMQP host to connect to', :short => 'H', :default => 'localhost'
43
43
  opt :port, 'The AMQP port to connect to', :short => 'P', :default => 5672
44
44
  opt :vhost, 'The vhost to connect to', :short => 'V', :default => '/'
@@ -20,6 +20,14 @@ class AmqpUtils::MessageFormatter
20
20
  def self.inherited(klass)
21
21
  ::AmqpUtils::MessageFormatter.register_formatter(klass, klass.basename)
22
22
  end
23
+
24
+ def generate(io, header, message)
25
+ raise NotImplementedError, "#{self} does not know how to generate output"
26
+ end
27
+
28
+ def load(io)
29
+ raise NotImplementedError, "#{self} does not know how consume its output"
30
+ end
23
31
  end
24
32
 
25
33
  class Pretty < Base
@@ -37,11 +45,20 @@ class AmqpUtils::MessageFormatter
37
45
  json_obj = {'header' => header.properties, 'message' => message}
38
46
  io.puts ::JSON.generate(json_obj)
39
47
  end
48
+
49
+ def load(io)
50
+ next_line = io.gets
51
+ ::JSON.parse(next_line) if next_line
52
+ end
40
53
  end
41
54
 
42
55
  class Message < Base
43
56
  def generate(io, header, message)
44
57
  io.puts message
45
58
  end
59
+
60
+ def load(io)
61
+ io.gets
62
+ end
46
63
  end
47
64
  end
@@ -0,0 +1,55 @@
1
+ class AmqpUtils::Serialization
2
+ def self.deserialize(content_type, message)
3
+ if serializer = serializers[content_type]
4
+ serializer.deserialize(message)
5
+ else
6
+ message
7
+ end
8
+ end
9
+
10
+ def self.serialize(content_type, message)
11
+ if serializer = serializers[content_type]
12
+ serializer.serialize(message)
13
+ else
14
+ message
15
+ end
16
+ end
17
+
18
+ def self.serializers
19
+ @@serializers ||= {}
20
+ end
21
+
22
+ class Base
23
+ def self.content_type(*content_types)
24
+ content_types.each do |ctype|
25
+ AmqpUtils::Serialization.serializers[ctype] = self
26
+ end
27
+ end
28
+ end
29
+
30
+ class MsgPack < Base
31
+ content_type 'application/msgpack'
32
+
33
+ def self.deserialize(message)
34
+ require 'msgpack'
35
+ MessagePack.unpack(message)
36
+ end
37
+
38
+ def self.serialize(message)
39
+ require 'msgpack'
40
+ message.to_msgpack
41
+ end
42
+ end
43
+
44
+ class Json < Base
45
+ content_type 'text/json'
46
+
47
+ def self.deserialize(message)
48
+ ::JSON.parse(message)
49
+ end
50
+
51
+ def self.serialize(message)
52
+ ::JSON.generate(message)
53
+ end
54
+ end
55
+ end
data/lib/amqp_utils.rb CHANGED
@@ -11,7 +11,7 @@ gem 'trollop'
11
11
  require 'trollop'
12
12
 
13
13
  gem 'amqp'
14
- require 'mq'
14
+ require 'amqp'
15
15
 
16
16
  gem 'facets'
17
17
  require 'facets/string/tab'
@@ -23,3 +23,6 @@ require 'clio/consoleutils'
23
23
 
24
24
  gem 'json'
25
25
  require 'json'
26
+
27
+ gem 'heredoc_unindent'
28
+ require 'heredoc_unindent'
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: 19
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.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-02-02 00:00:00 -06:00
18
+ date: 2011-06-20 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 9
29
+ hash: 1
30
30
  segments:
31
31
  - 0
32
- - 6
33
32
  - 7
34
- version: 0.6.7
33
+ - 1
34
+ version: 0.7.1
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- hash: 59
45
+ hash: 83
46
46
  segments:
47
47
  - 1
48
- - 10
48
+ - 16
49
49
  - 2
50
- version: 1.10.2
50
+ version: 1.16.2
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
@@ -98,6 +98,22 @@ dependencies:
98
98
  version: 1.1.6
99
99
  type: :runtime
100
100
  version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: heredoc_unindent
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ hash: 23
110
+ segments:
111
+ - 1
112
+ - 1
113
+ - 2
114
+ version: 1.1.2
115
+ type: :runtime
116
+ version_requirements: *id006
101
117
  description: |-
102
118
  Command line utilies for interacting with AMQP compliant queues.
103
119
  The intention is provide simple management tools that can be used to complete ad hoc
@@ -105,20 +121,20 @@ description: |-
105
121
  when needed.
106
122
  email: dougbarth@gmail.com
107
123
  executables:
124
+ - amqp-peek
108
125
  - amqp-deleteq
109
126
  - amqp-dequeue
110
- - amqp-enqueue
111
- - amqp-peek
127
+ - amqp-unbind
128
+ - amqp-statq
112
129
  - amqp-pop
113
- - amqp-purge
130
+ - amqp-enqueue
114
131
  - amqp-spy
115
- - amqp-statq
132
+ - amqp-purge
116
133
  extensions: []
117
134
 
118
135
  extra_rdoc_files:
119
136
  - README.txt
120
137
  files:
121
- - .gitignore
122
138
  - History.txt
123
139
  - License.txt
124
140
  - README.txt
@@ -134,9 +150,11 @@ files:
134
150
  - bin/amqp-purge
135
151
  - bin/amqp-spy
136
152
  - bin/amqp-statq
153
+ - bin/amqp-unbind
137
154
  - lib/amqp_utils.rb
138
155
  - lib/amqp_utils/command.rb
139
156
  - lib/amqp_utils/message_formatter.rb
157
+ - lib/amqp_utils/serialization.rb
140
158
  - test/test_amqp_utils.rb
141
159
  - test/test_helper.rb
142
160
  has_rdoc: true
@@ -144,8 +162,8 @@ homepage: http://github.com/dougbarth/amqp-utils
144
162
  licenses: []
145
163
 
146
164
  post_install_message:
147
- rdoc_options:
148
- - --charset=UTF-8
165
+ rdoc_options: []
166
+
149
167
  require_paths:
150
168
  - lib
151
169
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -169,10 +187,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
187
  requirements: []
170
188
 
171
189
  rubyforge_project: amqp-utils
172
- rubygems_version: 1.3.7
190
+ rubygems_version: 1.4.2
173
191
  signing_key:
174
192
  specification_version: 3
175
193
  summary: Command line utilities for interacting with AMQP compliant queues
176
- test_files:
177
- - test/test_amqp_utils.rb
178
- - test/test_helper.rb
194
+ test_files: []
195
+
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- .sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg