amqpcat 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,13 +16,13 @@ Usage: #{$0} [options] amqp-url
16
16
  'user:pass' : optional. Default: guest:guest
17
17
  'host' : required.
18
18
  'port' : optional. Default: 5672 (amqp), 5671 (amqps)
19
- 'vhost : optional. Default: /
19
+ 'vhost' : optional. Default: /
20
20
 
21
21
  Options:
22
22
  EOS
23
23
 
24
24
  opts.on('-h', '--help', 'Display usage') { puts opts; exit 0 }
25
-
25
+
26
26
  options[:mode] = nil
27
27
  opts.on('-c', '--consumer', 'Read data from the queue specified by -n and write to STDOUT') do
28
28
  options[:mode] = :consumer
@@ -39,42 +39,46 @@ EOS
39
39
  opts.on('-r', '--ssl-cert FILE', 'Use SSL cert in FILE.') do |f|
40
40
  options[:ssl_cert] = f
41
41
  end
42
-
42
+
43
43
  options[:verify_ssl] = true
44
44
  opts.on('y', '--[no-]verify-ssl', 'Verify server SSL certficiate. (Default: true)') do |y|
45
45
  options[:verify_ssl] = y
46
46
  end
47
-
47
+
48
48
  options[:prefix] = ''
49
49
  opts.on('-s', '--string STRING', "prefix output with STRING") do |s|
50
50
  options[:prefix] = s
51
51
  end
52
-
52
+
53
53
  options[:once] = false
54
54
  opts.on('-o', '--once', "Read/Write one message then exit. (Default: false)") do
55
55
  options[:once] = true
56
56
  end
57
-
57
+
58
58
  options[:name] = 'amqpcat.default'
59
59
  opts.on('-n', '--name NAME', "Queue and Exchange NAME to use. (Default: amqpcat.default)") do |name|
60
60
  options[:name] = name
61
61
  end
62
-
62
+
63
63
  options[:type] = 'direct'
64
64
  opts.on('-t', '--type TYPE', "Exchange type: direct, fanout. (Default: direct)") do |type|
65
65
  options[:type] = type
66
66
  end
67
-
67
+
68
68
  options[:durable] = true
69
69
  opts.on('--[no-]durable', "Enable/Disable durable messages. (Default: durable=true)") do |d|
70
70
  options[:durable] = d
71
71
  end
72
-
72
+
73
73
  options[:auto_delete] = false
74
74
  opts.on('--[no-]auto_delete', "Enable/Disable auto_delete. (Default: auto_delete=false)") do |d|
75
75
  options[:auto_delete] = d
76
76
  end
77
-
77
+
78
+ opts.on('--routing-key KEY', "Bind or publish to the exchange with a routing key.") do |k|
79
+ options[:routing_key] = k
80
+ end
81
+
78
82
  end
79
83
  optparse.parse!
80
84
 
@@ -84,7 +88,7 @@ if ARGV.size < 1
84
88
  end
85
89
 
86
90
  if options[:mode].nil?
87
- puts "Must specify --consumer or --producer. --help for help"
91
+ puts "Must specify --consumer or --publisher. --help for help"
88
92
  exit 1
89
93
  end
90
94
 
@@ -111,4 +115,4 @@ case options[:mode]
111
115
  end
112
116
  end
113
117
 
114
- amqpcat.finish
118
+ amqpcat.finish
@@ -6,58 +6,49 @@ class Amqpcat
6
6
 
7
7
  def initialize(url, options={})
8
8
  parse_amqp_url(url)
9
-
10
- @@opts = {:type => 'direct',
11
- :name => DEFAULT_QUEUE,
12
- :durable => true,
13
- :auto_delete => false,
14
- :ssl_key => nil,
15
- :ssl_cert => nil,
16
- :verify_ssl => true,
17
- }.merge(options)
18
-
19
- @@amqp_settings.merge!(@@opts)
20
- @@amqp = Bunny.new(@@amqp_settings)
21
- @@amqp.start
22
9
 
23
- name = @@opts[:name]
24
- type = @@opts[:type]
25
- durable = @@opts[:durable]
26
- auto_delete = @@opts[:auto_delete]
27
-
28
- if type == 'fanout'
29
- @@queue = @@amqp.queue(:durable => durable, :auto_delete => auto_delete)
30
- else
31
- @@queue = @@amqp.queue(name, :durable => durable, :auto_delete => auto_delete)
32
- end
33
- @@exch = @@amqp.exchange(name, :type => type, :durable => durable, :auto_delete => auto_delete)
34
- @@queue.bind(@@exch)
10
+ @opts = {
11
+ :type => 'direct',
12
+ :name => DEFAULT_QUEUE,
13
+ :durable => true,
14
+ :auto_delete => false,
15
+ :persistent => true,
16
+ :ssl_key => nil,
17
+ :ssl_cert => nil,
18
+ :verify_ssl => true,
19
+ }.merge(options)
20
+
21
+ @amqp_settings.merge!(@opts)
22
+ @amqp = Bunny.new(@amqp_settings)
23
+ @amqp.start
35
24
  end
36
-
25
+
37
26
  def publish(msg)
38
- @@exch.publish(msg)
27
+ exchange.publish(msg, :persistent => @opts[:persistent], :key => @opts[:routing_key])
39
28
  end
40
-
29
+
41
30
  def message_count
42
- @@queue.message_count
31
+ queue.message_count
43
32
  end
44
-
33
+
45
34
  def fetch
46
- @@queue.pop[:payload]
35
+ queue.pop[:payload]
47
36
  end
48
-
37
+
49
38
  def subscribe(&block)
50
- @@queue.subscribe(&block)
39
+ queue.subscribe(&block)
51
40
  end
52
-
41
+
53
42
  def finish
54
- @@amqp.stop
43
+ @amqp.stop
55
44
  end
56
-
45
+
46
+ private
47
+
57
48
  def parse_amqp_url(str)
58
49
  url = URI.parse(str)
59
50
  use_ssl = url.scheme.downcase == 'amqps'
60
- @@amqp_settings = {
51
+ @amqp_settings = {
61
52
  :host => url.host,
62
53
  :port => url.port || (use_ssl ? 5671 : 5672),
63
54
  :user => url.user || 'guest',
@@ -67,4 +58,29 @@ class Amqpcat
67
58
  }
68
59
  end
69
60
 
61
+ def exchange
62
+ return @exchange if @exchange
63
+ options = {
64
+ :type => @opts[:type],
65
+ :durable => @opts[:durable],
66
+ :auto_delete => @opts[:auto_delete]
67
+ }
68
+ @exchange = @amqp.exchange(@opts[:name], options)
69
+ end
70
+
71
+ def queue
72
+ return @queue if @queue
73
+ options = {
74
+ :durable => @opts[:durable],
75
+ :auto_delete => @opts[:auto_delete]
76
+ }
77
+ @queue = case @opts[:type]
78
+ when 'fanout'
79
+ @amqp.queue(options)
80
+ else
81
+ @amqp.queue(@opts[:name], options)
82
+ end
83
+ @queue.bind(exchange, :routing_key => @opts[:routing_key])
84
+ @queue
85
+ end
70
86
  end
@@ -1,3 +1,3 @@
1
1
  module Amqpcat
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,27 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amqpcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
4
  prerelease:
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joe Miller
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-05 00:00:00.000000000Z
12
+ date: 2012-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bunny
16
- requirement: &70278690104680 !ruby/object:Gem::Requirement
15
+ type: :runtime
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - =
19
+ - - '='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 0.7.8
22
- type: :runtime
23
22
  prerelease: false
24
- version_requirements: *70278690104680
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - '='
27
+ - !ruby/object:Gem::Version
28
+ version: 0.7.8
29
+ name: bunny
25
30
  description: ! 'A netcat inspired command line tool for reading and writing simple
26
31
 
27
32
  messages to AMQP based message brokers such as RabbitMQ.
@@ -30,22 +35,18 @@ description: ! 'A netcat inspired command line tool for reading and writing simp
30
35
  email: joeym@joeym.net
31
36
  executables:
32
37
  - amqpcat
33
- - amqpcat.bak
34
38
  extensions: []
35
39
  extra_rdoc_files: []
36
40
  files:
37
- - amqpcat.gemspec
38
- - bin/amqpcat
39
- - bin/amqpcat.bak
40
- - examples/client_cert.pem
41
- - examples/client_key.pem
42
- - examples/test_direct.sh
43
- - examples/test_fanout.sh
44
- - examples/test_ssl.sh
45
41
  - Gemfile
46
42
  - Gemfile.lock
43
+ - bin/amqpcat
47
44
  - lib/amqpcat/version.rb
48
45
  - lib/amqpcat.rb
46
+ - examples/test_ssl.sh
47
+ - examples/test_direct.sh
48
+ - examples/test_fanout.sh
49
+ - amqpcat.gemspec
49
50
  - README.md
50
51
  homepage: https://github.com/joemiller/amqpcat
51
52
  licenses: []
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
68
  version: '0'
68
69
  requirements: []
69
70
  rubyforge_project:
70
- rubygems_version: 1.8.10
71
+ rubygems_version: 1.8.24
71
72
  signing_key:
72
73
  specification_version: 3
73
74
  summary: Netcat-like tool for reading and writing messages to AMQP message brokers
@@ -1,115 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.dirname(__FILE__) + '/../lib')
4
-
5
- require 'optparse'
6
- require 'amqpcat'
7
-
8
- options = {}
9
- optparse = OptionParser.new do |opts|
10
- opts.banner = <<-EOS
11
- Usage: #{$0} [options] amqp-url
12
-
13
- amqp-url format: 'amqp://user:pass@host:port/vhost'
14
-
15
- 'amqp' : required. Either amqp or amqps (SSL)
16
- 'user:pass' : optional. Default: guest:guest
17
- 'host' : required.
18
- 'port' : optional. Default: 5672 (amqp), 5671 (amqps)
19
- 'vhost : optional. Default: /
20
-
21
- Options:
22
- EOS
23
-
24
- opts.on('-h', '--help', 'Display usage') { puts opts; exit 0 }
25
-
26
- options[:mode] = nil
27
- opts.on('-c', '--consumer', 'Read data from the queue specified by -n and write to STDOUT') do
28
- options[:mode] = :consumer
29
- end
30
-
31
- opts.on('-p', '--publisher', 'Read data from STDIN and publish to the exchange specified by -n') do
32
- options[:mode] = :publisher
33
- end
34
-
35
-
36
- opts.on('-k', '--ssl-key FILE', 'Use SSL key in FILE.') do |f|
37
- options[:ssl_key] = f
38
- end
39
-
40
- opts.on('-r', '--ssl-cert FILE', 'Use SSL cert in FILE.') do |f|
41
- options[:ssl_cert] = f
42
- end
43
-
44
- options[:ssl_verify] = true
45
- opts.on('y', '--[no-]ssl-verify', 'Verify server SSL certficiate. (Default: true)') do |y|
46
- options[:ssl_verify] = y
47
- end
48
-
49
- options[:prefix] = ''
50
- opts.on('-s', '--string STRING', "prefix output with STRING") do |s|
51
- options[:prefix] = s
52
- end
53
-
54
- options[:once] = false
55
- opts.on('-o', '--once', "Read/Write one message then exit. (Default: false)") do
56
- options[:once] = true
57
- end
58
-
59
- options[:name] = 'amqpcat.default'
60
- opts.on('-n', '--name NAME', "Queue and Exchange NAME to use. (Default: amqpcat.default)") do |name|
61
- options[:name] = name
62
- end
63
-
64
- options[:type] = 'direct'
65
- opts.on('-t', '--type TYPE', "Exchange type: direct, fanout. (Default: direct)") do |type|
66
- options[:type] = type
67
- end
68
-
69
- options[:durable] = true
70
- opts.on('--[no-]durable', "Enable/Disable durable messages. (Default: durable=true)") do |d|
71
- options[:durable] = d
72
- end
73
-
74
- options[:auto_delete] = false
75
- opts.on('--[no-]auto_delete', "Enable/Disable auto_delete. (Default: auto_delete=false)") do |d|
76
- options[:auto_delete] = d
77
- end
78
-
79
- end
80
- optparse.parse!
81
-
82
- if ARGV.size < 1
83
- puts "Must specify amqp-url. --help for help"
84
- exit 1
85
- end
86
-
87
- if options[:mode].nil?
88
- puts "Must specify --consumer or --producer. --help for help"
89
- exit 1
90
- end
91
-
92
- amqp_url = ARGV[0]
93
- amqpcat = Amqpcat.new(amqp_url, options)
94
-
95
- trap 'SIGINT', proc { amqpcat.finish; exit 0 }
96
-
97
- # case options[:mode]
98
- # when :consumer
99
- amqpcat.subscribe do |msg|
100
- $stdout.write options[:prefix] + msg[:payload]
101
- $stdout.flush
102
- if options[:once]
103
- amqpcat.finish
104
- exit
105
- end
106
- end
107
- # when :publisher
108
- if options[:once]
109
- amqpcat.publish $stdin.read
110
- else
111
- $stdin.each_line { |l| amqpcat.publish(l) }
112
- end
113
- # end
114
-
115
- amqpcat.finish
@@ -1,18 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIC4zCCAcugAwIBAgIBAjANBgkqhkiG9w0BAQUFADARMQ8wDQYDVQQDEwZUZXN0
3
- Q0EwHhcNMTIwMTE1MDAwMjE1WhcNMTMwMTE0MDAwMjE1WjAoMRUwEwYDVQQDEwxz
4
- ZW5zdS1zZXJ2ZXIxDzANBgNVBAoTBmNsaWVudDCCASIwDQYJKoZIhvcNAQEBBQAD
5
-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