amqpcat 0.0.1
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.
- data/Gemfile +3 -0
- data/Gemfile.lock +15 -0
- data/README.md +106 -0
- data/amqpcat.gemspec +32 -0
- data/bin/amqpcat +114 -0
- data/bin/amqpcat.bak +115 -0
- data/examples/client_cert.pem +18 -0
- data/examples/client_key.pem +27 -0
- data/examples/test_direct.sh +20 -0
- data/examples/test_fanout.sh +21 -0
- data/examples/test_ssl.sh +24 -0
- data/lib/amqpcat.rb +70 -0
- data/lib/amqpcat/version.rb +3 -0
- metadata +74 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
amqpcat - Netcat-like tool for AMQP queues
|
2
|
+
==========================================
|
3
|
+
|
4
|
+
This was originally written as a "toy" to learn and experiment with
|
5
|
+
rabbitmq. It allows you to easily read/write from AMQP queues/exchanges
|
6
|
+
from the command line or from shell scripts. It is implemented with the
|
7
|
+
`bunny` Ruby gem.
|
8
|
+
|
9
|
+
Install
|
10
|
+
-------
|
11
|
+
Install from gem:
|
12
|
+
|
13
|
+
sudo gem install amqpcat
|
14
|
+
|
15
|
+
Install from github:
|
16
|
+
|
17
|
+
git clone https://github.com/joemiller/amqpcat
|
18
|
+
gem build amqpcat.gemspec
|
19
|
+
gem install amqpcat-0.0.1.gem
|
20
|
+
|
21
|
+
Example Usage
|
22
|
+
-------------
|
23
|
+
|
24
|
+
### 1:1 Messaging
|
25
|
+
|
26
|
+
Start a consumer. This will block until a message is received.
|
27
|
+
|
28
|
+
amqpcat --consumer amqp://guest:guest@rabbitmq.server/
|
29
|
+
|
30
|
+
Publish a message:
|
31
|
+
|
32
|
+
echo "hello rabbit" | amqpcat --publisher amqp://guest:guest@rabbitmq.server/
|
33
|
+
|
34
|
+
The consumer should output the message and exit.
|
35
|
+
|
36
|
+
### 1:N (fanout / pubsub)
|
37
|
+
|
38
|
+
See the `examples/test_fanout.sh` script for another example of fanout
|
39
|
+
messaging.
|
40
|
+
|
41
|
+
Start 2 consumers, using `-s` to prefix the output of each with an
|
42
|
+
identifying string:
|
43
|
+
|
44
|
+
amqpcat --consumer -n fanout.test -t fanout -s "Consumer 1: " amqp://guest:guest@rabbitmq.server/
|
45
|
+
amqpcat --consumer -n fanout.test -t fanout -s "Consumer 2: " amqp://guest:guest@rabbitmq.server/
|
46
|
+
|
47
|
+
Note: In fanout mode, consumers will create their own server-named queues and bind to an exchange
|
48
|
+
defined by the `-n` parameter.
|
49
|
+
|
50
|
+
Published a message to the exchange:
|
51
|
+
|
52
|
+
echo "hello rabbits" | amqpcat --publisher -n fanout.test -t fanout amqp://guest:guest@rabbitmq.server/
|
53
|
+
|
54
|
+
Both of the consumers should print out the message we published.
|
55
|
+
|
56
|
+
Options
|
57
|
+
-------
|
58
|
+
Run `amqpcat -h` to get detailed help output.
|
59
|
+
|
60
|
+
### One-message -vs- Continuous message mode
|
61
|
+
|
62
|
+
By default, when publishing, `amqpcat` will use the newline character to
|
63
|
+
distinguish between messages to publish. However, you can send a single
|
64
|
+
message by using the `--once` option. This can be useful if you need
|
65
|
+
to send a single message that contains new lines.
|
66
|
+
|
67
|
+
SSL Support
|
68
|
+
-----------
|
69
|
+
SSL support has been written but is not tested nor is it fully working
|
70
|
+
at this time (v0.0.1).
|
71
|
+
|
72
|
+
Additionally, the --ssl-key and --ssl-cert options are only supported
|
73
|
+
under newer versions of the Bunny gem (0.8+) or if bunny is installed
|
74
|
+
from the master branch on github.
|
75
|
+
|
76
|
+
Contributing
|
77
|
+
------------
|
78
|
+
1. Fork it.
|
79
|
+
2. Create a branch (`git checkout -b my_feature`)
|
80
|
+
3. Commit your changes (`git commit -am "did some stuff"`)
|
81
|
+
4. Push to the branch (`git push origin my_feature`)
|
82
|
+
5. Create an with a link to your branch
|
83
|
+
|
84
|
+
Author
|
85
|
+
------
|
86
|
+
|
87
|
+
Joe Miller - http://twitter.com/miller_joe || https://github.com/joemiller
|
88
|
+
|
89
|
+
License
|
90
|
+
-------
|
91
|
+
|
92
|
+
Author:: Joe Miller (<joeym@joeym.net>)
|
93
|
+
Copyright:: Copyright (c) 2012 Joe Miller
|
94
|
+
License:: Apache License, Version 2.0
|
95
|
+
|
96
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
97
|
+
you may not use this file except in compliance with the License.
|
98
|
+
You may obtain a copy of the License at
|
99
|
+
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
101
|
+
|
102
|
+
Unless required by applicable law or agreed to in writing, software
|
103
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
104
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
105
|
+
See the License for the specific language governing permissions and
|
106
|
+
limitations under the License.
|
data/amqpcat.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
$:.push('lib')
|
4
|
+
require "amqpcat/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "amqpcat"
|
8
|
+
s.version = Amqpcat::VERSION.dup
|
9
|
+
s.date = "2012-02-05"
|
10
|
+
s.summary = "Netcat-like tool for reading and writing messages to AMQP message brokers"
|
11
|
+
s.email = "joeym@joeym.net"
|
12
|
+
s.homepage = "https://github.com/joemiller/amqpcat"
|
13
|
+
s.authors = ['Joe Miller']
|
14
|
+
|
15
|
+
s.description = <<-EOF
|
16
|
+
A netcat inspired command line tool for reading and writing simple
|
17
|
+
messages to AMQP based message brokers such as RabbitMQ.
|
18
|
+
EOF
|
19
|
+
|
20
|
+
s.files = Dir['**/*']
|
21
|
+
s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
|
22
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
|
25
|
+
## Make sure you can build the gem on older versions of RubyGems too:
|
26
|
+
s.rubygems_version = "1.3.6"
|
27
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
28
|
+
s.specification_version = 3 if s.respond_to? :specification_version
|
29
|
+
|
30
|
+
s.add_dependency("bunny", "0.7.8")
|
31
|
+
|
32
|
+
end
|
data/bin/amqpcat
ADDED
@@ -0,0 +1,114 @@
|
|
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
|
+
opts.on('-k', '--ssl-key FILE', 'Use SSL key in FILE.') do |f|
|
36
|
+
options[:ssl_key] = f
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on('-r', '--ssl-cert FILE', 'Use SSL cert in FILE.') do |f|
|
40
|
+
options[:ssl_cert] = f
|
41
|
+
end
|
42
|
+
|
43
|
+
options[:verify_ssl] = true
|
44
|
+
opts.on('y', '--[no-]verify-ssl', 'Verify server SSL certficiate. (Default: true)') do |y|
|
45
|
+
options[:verify_ssl] = y
|
46
|
+
end
|
47
|
+
|
48
|
+
options[:prefix] = ''
|
49
|
+
opts.on('-s', '--string STRING', "prefix output with STRING") do |s|
|
50
|
+
options[:prefix] = s
|
51
|
+
end
|
52
|
+
|
53
|
+
options[:once] = false
|
54
|
+
opts.on('-o', '--once', "Read/Write one message then exit. (Default: false)") do
|
55
|
+
options[:once] = true
|
56
|
+
end
|
57
|
+
|
58
|
+
options[:name] = 'amqpcat.default'
|
59
|
+
opts.on('-n', '--name NAME', "Queue and Exchange NAME to use. (Default: amqpcat.default)") do |name|
|
60
|
+
options[:name] = name
|
61
|
+
end
|
62
|
+
|
63
|
+
options[:type] = 'direct'
|
64
|
+
opts.on('-t', '--type TYPE', "Exchange type: direct, fanout. (Default: direct)") do |type|
|
65
|
+
options[:type] = type
|
66
|
+
end
|
67
|
+
|
68
|
+
options[:durable] = true
|
69
|
+
opts.on('--[no-]durable', "Enable/Disable durable messages. (Default: durable=true)") do |d|
|
70
|
+
options[:durable] = d
|
71
|
+
end
|
72
|
+
|
73
|
+
options[:auto_delete] = false
|
74
|
+
opts.on('--[no-]auto_delete', "Enable/Disable auto_delete. (Default: auto_delete=false)") do |d|
|
75
|
+
options[:auto_delete] = d
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
optparse.parse!
|
80
|
+
|
81
|
+
if ARGV.size < 1
|
82
|
+
puts "Must specify amqp-url. --help for help"
|
83
|
+
exit 1
|
84
|
+
end
|
85
|
+
|
86
|
+
if options[:mode].nil?
|
87
|
+
puts "Must specify --consumer or --producer. --help for help"
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
|
91
|
+
amqp_url = ARGV[0]
|
92
|
+
amqpcat = Amqpcat.new(amqp_url, options)
|
93
|
+
|
94
|
+
trap 'SIGINT', proc { amqpcat.finish; exit 0 }
|
95
|
+
|
96
|
+
case options[:mode]
|
97
|
+
when :consumer
|
98
|
+
amqpcat.subscribe do |msg|
|
99
|
+
$stdout.write options[:prefix] + msg[:payload]
|
100
|
+
$stdout.flush
|
101
|
+
if options[:once]
|
102
|
+
amqpcat.finish
|
103
|
+
exit
|
104
|
+
end
|
105
|
+
end
|
106
|
+
when :publisher
|
107
|
+
if options[:once]
|
108
|
+
amqpcat.publish $stdin.read
|
109
|
+
else
|
110
|
+
$stdin.each_line { |l| amqpcat.publish(l) }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
amqpcat.finish
|
data/bin/amqpcat.bak
ADDED
@@ -0,0 +1,115 @@
|
|
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
|
@@ -0,0 +1,18 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIC4zCCAcugAwIBAgIBAjANBgkqhkiG9w0BAQUFADARMQ8wDQYDVQQDEwZUZXN0
|
3
|
+
Q0EwHhcNMTIwMTE1MDAwMjE1WhcNMTMwMTE0MDAwMjE1WjAoMRUwEwYDVQQDEwxz
|
4
|
+
ZW5zdS1zZXJ2ZXIxDzANBgNVBAoTBmNsaWVudDCCASIwDQYJKoZIhvcNAQEBBQAD
|
5
|
+
ggEPADCCAQoCggEBAM3Ib3MoKvu4CsEzGcQDN0u7Vo+7Pt7c6imcIg8Mktastbzl
|
6
|
+
BhWjZt9nBdQZ9tL6Cj/HMnhw3FsfQ4kmNgcoFDmoaFqi0oHVAD0xXauu2LF3G1aq
|
7
|
+
Qr2e02hqnrvc2BKDnoW4n9h+AfmNiAQ3bb572jJv49NDHRscuxD+4/ZJCH+uN5lp
|
8
|
+
uuME/HvhNjR9yo3kc8mK1iUNpYa25qmoE/3Ao26FUrAgSbLG6RP3uXuXZlWrfnAt
|
9
|
+
py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ZQpGlSasfA6r/q7
|
22
|
+
9ucGLzPGhZ7qmk567d/UChj6G3uLohxipWHLjWlhLTtG6jk6felLN96vcJDz2BDw
|
23
|
+
Z2dW25ybxuZa2NTt0FM+3JqnTLBItO8i9P5sM7bTC5WwrWfT0w+g8pySrhdSjFgu
|
24
|
+
zzc6HwKBgQCtyYw6gqqo0a7iYulVYXXHLJ/TYcw3qNdLz5bRTu7yFlMlLQXJ3XFk
|
25
|
+
svUKHnx9AMIFQ+Dz02WFVckeVqarJ7T2ENPmHem64TAP2yblfThfc0XZYbHQRMwj
|
26
|
+
qc5KkG+5BxWBpLqYxYPz68M6l5P1OX5pudC5XfFSFz2KkLyQFq8lYw==
|
27
|
+
-----END RSA PRIVATE KEY-----
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
amqpcat_bin="`dirname $0`/../bin/amqpcat"
|
4
|
+
|
5
|
+
url="amqp://guest:guest@rabbitmq/"
|
6
|
+
opts="--name=direct.test --type=direct"
|
7
|
+
|
8
|
+
## start 2 consumers ##
|
9
|
+
$amqpcat_bin -s "Consumer 1: " --consumer $url $opts &
|
10
|
+
$amqpcat_bin -s "Consumer 2: " --consumer $url $opts &
|
11
|
+
|
12
|
+
## send messages ##
|
13
|
+
echo "test direct queue: 1" | $amqpcat_bin --publisher $url $opts
|
14
|
+
echo "test direct queue: 2" | $amqpcat_bin --publisher $url $opts
|
15
|
+
echo "test direct queue: 3" | $amqpcat_bin --publisher $url $opts
|
16
|
+
echo "test direct queue: 4" | $amqpcat_bin --publisher $url $opts
|
17
|
+
|
18
|
+
## kill the consumers we forked ##
|
19
|
+
sleep 1
|
20
|
+
kill %1 %2
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
amqpcat_bin="`dirname $0`/../bin/amqpcat"
|
4
|
+
|
5
|
+
amqp_url="amqp://guest:guest@rabbitmq/"
|
6
|
+
amqp_opts="--name=fanout.test --type=fanout"
|
7
|
+
|
8
|
+
## start 2 consumers ##
|
9
|
+
$amqpcat_bin -s "Consumer 1: " $amqp_url $amqp_opts &
|
10
|
+
$amqpcat_bin -s "Consumer 2: " $amqp_url $amqp_opts &
|
11
|
+
sleep 1
|
12
|
+
|
13
|
+
## send messages ##
|
14
|
+
echo "test fanout queue: 1" | $amqpcat_bin $amqp_url $amqp_opts
|
15
|
+
echo "test fanout queue: 2" | $amqpcat_bin $amqp_url $amqp_opts
|
16
|
+
echo "test fanout queue: 3" | $amqpcat_bin $amqp_url $amqp_opts
|
17
|
+
echo "test fanout queue: 4" | $amqpcat_bin $amqp_url $amqp_opts
|
18
|
+
|
19
|
+
## kill the consumers we forked ##
|
20
|
+
sleep 1
|
21
|
+
kill %1 %2
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
whereami=$(dirname $0)
|
4
|
+
amqpcat_bin="$whereami/../bin/amqpcat"
|
5
|
+
|
6
|
+
url="amqps://guest:guest@rabbitmq/"
|
7
|
+
opts="--name=direct.test --type=direct \
|
8
|
+
--ssl-key=$whereami/client_key.pem \
|
9
|
+
--ssl-cert=$whereami/client_cert.pem\
|
10
|
+
--no-verify-ssl"
|
11
|
+
|
12
|
+
## start 2 consumers ##
|
13
|
+
$amqpcat_bin -s "Consumer 1: " --consumer $url $opts &
|
14
|
+
$amqpcat_bin -s "Consumer 2: " --consumer $url $opts &
|
15
|
+
|
16
|
+
## send messages ##
|
17
|
+
echo "test direct queue: 1" | $amqpcat_bin --publisher $url $opts
|
18
|
+
echo "test direct queue: 2" | $amqpcat_bin --publisher $url $opts
|
19
|
+
echo "test direct queue: 3" | $amqpcat_bin --publisher $url $opts
|
20
|
+
echo "test direct queue: 4" | $amqpcat_bin --publisher $url $opts
|
21
|
+
|
22
|
+
## kill the consumers we forked ##
|
23
|
+
sleep 1
|
24
|
+
kill %1 %2
|
data/lib/amqpcat.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'bunny'
|
3
|
+
|
4
|
+
class Amqpcat
|
5
|
+
DEFAULT_QUEUE = 'amqpcat.default'
|
6
|
+
|
7
|
+
def initialize(url, options={})
|
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
|
+
|
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)
|
35
|
+
end
|
36
|
+
|
37
|
+
def publish(msg)
|
38
|
+
@@exch.publish(msg)
|
39
|
+
end
|
40
|
+
|
41
|
+
def message_count
|
42
|
+
@@queue.message_count
|
43
|
+
end
|
44
|
+
|
45
|
+
def fetch
|
46
|
+
@@queue.pop[:payload]
|
47
|
+
end
|
48
|
+
|
49
|
+
def subscribe(&block)
|
50
|
+
@@queue.subscribe(&block)
|
51
|
+
end
|
52
|
+
|
53
|
+
def finish
|
54
|
+
@@amqp.stop
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_amqp_url(str)
|
58
|
+
url = URI.parse(str)
|
59
|
+
use_ssl = url.scheme.downcase == 'amqps'
|
60
|
+
@@amqp_settings = {
|
61
|
+
:host => url.host,
|
62
|
+
:port => url.port || (use_ssl ? 5671 : 5672),
|
63
|
+
:user => url.user || 'guest',
|
64
|
+
:pass => url.password || 'guest',
|
65
|
+
:vhost => url.path == "" ? '/' : url.path,
|
66
|
+
:ssl => use_ssl,
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amqpcat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joe Miller
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bunny
|
16
|
+
requirement: &70278690104680 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - =
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.7.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70278690104680
|
25
|
+
description: ! 'A netcat inspired command line tool for reading and writing simple
|
26
|
+
|
27
|
+
messages to AMQP based message brokers such as RabbitMQ.
|
28
|
+
|
29
|
+
'
|
30
|
+
email: joeym@joeym.net
|
31
|
+
executables:
|
32
|
+
- amqpcat
|
33
|
+
- amqpcat.bak
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
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
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
47
|
+
- lib/amqpcat/version.rb
|
48
|
+
- lib/amqpcat.rb
|
49
|
+
- README.md
|
50
|
+
homepage: https://github.com/joemiller/amqpcat
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.10
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Netcat-like tool for reading and writing messages to AMQP message brokers
|
74
|
+
test_files: []
|