bunny 0.0.8
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/README.markdown +127 -0
- data/Rakefile +12 -0
- data/examples/simple.rb +35 -0
- data/lib/amqp.rb +15 -0
- data/lib/amqp/buffer.rb +274 -0
- data/lib/amqp/client.rb +171 -0
- data/lib/amqp/frame.rb +60 -0
- data/lib/amqp/protocol.rb +158 -0
- data/lib/amqp/spec.rb +832 -0
- data/lib/bunny.rb +67 -0
- data/lib/bunny/exchange.rb +54 -0
- data/lib/bunny/header.rb +30 -0
- data/lib/bunny/queue.rb +111 -0
- data/protocol/amqp-0.8.json +617 -0
- data/protocol/amqp-0.8.xml +3908 -0
- data/protocol/codegen.rb +173 -0
- data/spec/bunny_spec.rb +40 -0
- data/spec/exchange_spec.rb +65 -0
- data/spec/queue_spec.rb +51 -0
- metadata +73 -0
data/protocol/codegen.rb
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
name = 'amqp-0.8.json'
|
|
5
|
+
path = File.dirname(__FILE__)+'/'+name
|
|
6
|
+
s = JSON.parse(File.read(path))
|
|
7
|
+
|
|
8
|
+
# require 'pp'
|
|
9
|
+
# pp(s)
|
|
10
|
+
# exit
|
|
11
|
+
|
|
12
|
+
require 'erb'
|
|
13
|
+
|
|
14
|
+
puts ERB.new(%q[
|
|
15
|
+
#:stopdoc:
|
|
16
|
+
# this file was autogenerated on <%= Time.now.to_s %>
|
|
17
|
+
# using <%= name.ljust(16) %> (mtime: <%= File.mtime(path) %>)
|
|
18
|
+
#
|
|
19
|
+
# DO NOT EDIT! (edit protocol/codegen.rb instead, and run `rake codegen`)
|
|
20
|
+
|
|
21
|
+
module AMQP
|
|
22
|
+
HEADER = <%= s['name'].dump %>.freeze
|
|
23
|
+
VERSION_MAJOR = <%= s['major-version'] %>
|
|
24
|
+
VERSION_MINOR = <%= s['minor-version'] %>
|
|
25
|
+
PORT = <%= s['port'] %>
|
|
26
|
+
|
|
27
|
+
class Frame
|
|
28
|
+
def self.types
|
|
29
|
+
@types ||= {}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.Frame id
|
|
33
|
+
(@_base_frames ||= {})[id] ||= Class.new(Frame) do
|
|
34
|
+
class_eval %[
|
|
35
|
+
def self.inherited klass
|
|
36
|
+
klass.const_set(:ID, #{id})
|
|
37
|
+
Frame.types[#{id}] = klass
|
|
38
|
+
end
|
|
39
|
+
]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
<%- s['constants'].select{|c| (1..8).include? c['value'] }.each do |c| -%>
|
|
44
|
+
class <%= c['name'].gsub(/^FRAME-/,'').split('-').map{|w| w.downcase.capitalize}.join.ljust(9) -%> < Frame( <%= c['value'] -%> ); end
|
|
45
|
+
<%- end -%>
|
|
46
|
+
|
|
47
|
+
FOOTER = <%= frame_end = s['constants'].find{|c| c['name'] == 'FRAME-END' }['value'] %>
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
RESPONSES = {
|
|
51
|
+
<%- s['constants'].select{|c| c['value'] != frame_end and (200..500).include? c['value'] }.each do |c| -%>
|
|
52
|
+
<%= c['value'] %> => :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
|
|
53
|
+
<%- end -%>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
FIELDS = [
|
|
57
|
+
<%- s['domains'].select{|d| d.first == d.last }.each do |d| -%>
|
|
58
|
+
:<%= d.first -%>,
|
|
59
|
+
<%- end -%>
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
module Protocol
|
|
63
|
+
class Class
|
|
64
|
+
class << self
|
|
65
|
+
FIELDS.each do |f|
|
|
66
|
+
class_eval %[
|
|
67
|
+
def #{f} name
|
|
68
|
+
properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
|
|
69
|
+
attr_accessor name
|
|
70
|
+
end
|
|
71
|
+
]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def properties() @properties ||= [] end
|
|
75
|
+
|
|
76
|
+
def id() self::ID end
|
|
77
|
+
def name() self::NAME end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
class Method
|
|
81
|
+
class << self
|
|
82
|
+
FIELDS.each do |f|
|
|
83
|
+
class_eval %[
|
|
84
|
+
def #{f} name
|
|
85
|
+
arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
|
|
86
|
+
attr_accessor name
|
|
87
|
+
end
|
|
88
|
+
]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def arguments() @arguments ||= [] end
|
|
92
|
+
|
|
93
|
+
def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
|
|
94
|
+
def id() self::ID end
|
|
95
|
+
def name() self::NAME end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def == b
|
|
99
|
+
self.class.arguments.inject(true) do |eql, (type, name)|
|
|
100
|
+
eql and __send__("#{name}") == b.__send__("#{name}")
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.methods() @methods ||= {} end
|
|
106
|
+
|
|
107
|
+
def self.Method(id, name)
|
|
108
|
+
@_base_methods ||= {}
|
|
109
|
+
@_base_methods[id] ||= ::Class.new(Method) do
|
|
110
|
+
class_eval %[
|
|
111
|
+
def self.inherited klass
|
|
112
|
+
klass.const_set(:ID, #{id})
|
|
113
|
+
klass.const_set(:NAME, :#{name.to_s})
|
|
114
|
+
klass.parent.methods[#{id}] = klass
|
|
115
|
+
klass.parent.methods[klass::NAME] = klass
|
|
116
|
+
end
|
|
117
|
+
]
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def self.classes() @classes ||= {} end
|
|
123
|
+
|
|
124
|
+
def self.Class(id, name)
|
|
125
|
+
@_base_classes ||= {}
|
|
126
|
+
@_base_classes[id] ||= ::Class.new(Class) do
|
|
127
|
+
class_eval %[
|
|
128
|
+
def self.inherited klass
|
|
129
|
+
klass.const_set(:ID, #{id})
|
|
130
|
+
klass.const_set(:NAME, :#{name.to_s})
|
|
131
|
+
Protocol.classes[#{id}] = klass
|
|
132
|
+
Protocol.classes[klass::NAME] = klass
|
|
133
|
+
end
|
|
134
|
+
]
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
module AMQP
|
|
141
|
+
module Protocol
|
|
142
|
+
<%- s['classes'].each do |c| -%>
|
|
143
|
+
class <%= c['name'].capitalize.ljust(12) %> < Class( <%= c['id'].to_s.rjust(3) %>, :<%= c['name'].ljust(12) %> ); end
|
|
144
|
+
<%- end -%>
|
|
145
|
+
|
|
146
|
+
<%- s['classes'].each do |c| -%>
|
|
147
|
+
class <%= c['name'].capitalize %>
|
|
148
|
+
<%- c['properties'].each do |p| -%>
|
|
149
|
+
<%= p['type'].ljust(10) %> :<%= p['name'].tr('-','_') %>
|
|
150
|
+
<%- end if c['properties'] -%>
|
|
151
|
+
|
|
152
|
+
<%- c['methods'].each do |m| -%>
|
|
153
|
+
class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"}.ljust(12) %> < Method( <%= m['id'].to_s.rjust(3) %>, :<%= m['name'].tr('- ','_').ljust(14) %> ); end
|
|
154
|
+
<%- end -%>
|
|
155
|
+
|
|
156
|
+
<%- c['methods'].each do |m| -%>
|
|
157
|
+
class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"} %>
|
|
158
|
+
<%- m['arguments'].each do |a| -%>
|
|
159
|
+
<%- if a['domain'] -%>
|
|
160
|
+
<%= s['domains'].find{|k,v| k == a['domain']}.last.ljust(10) %> :<%= a['name'].tr('- ','_') %>
|
|
161
|
+
<%- else -%>
|
|
162
|
+
<%= a['type'].ljust(10) %> :<%= a['name'].tr('- ','_') %>
|
|
163
|
+
<%- end -%>
|
|
164
|
+
<%- end if m['arguments'] -%>
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
<%- end -%>
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
<%- end -%>
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
].gsub!(/^ /,''), nil, '>-%').result(binding)
|
data/spec/bunny_spec.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# bunny_spec.rb
|
|
2
|
+
|
|
3
|
+
# Assumes that target message broker/server has a user called 'guest' with a password 'guest'
|
|
4
|
+
# and that it is running on 'localhost'.
|
|
5
|
+
|
|
6
|
+
# If this is not the case, please change the 'Bunny.new' call below to include
|
|
7
|
+
# the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
|
|
8
|
+
|
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
|
|
10
|
+
|
|
11
|
+
describe Bunny do
|
|
12
|
+
|
|
13
|
+
before(:each) do
|
|
14
|
+
@b = Bunny.new
|
|
15
|
+
@b.start
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
after(:each) do
|
|
19
|
+
@b.stop
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should connect to an AMQP server" do
|
|
23
|
+
@b.status.should == 'CONNECTED'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should be able to create an exchange" do
|
|
27
|
+
exch = @b.exchange('test_exchange')
|
|
28
|
+
exch.should be_an_instance_of Exchange
|
|
29
|
+
exch.name.should == 'test_exchange'
|
|
30
|
+
@b.exchanges.has_key?('test_exchange').should be true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "should be able to create a queue" do
|
|
34
|
+
q = @b.queue('test1')
|
|
35
|
+
q.should be_an_instance_of Queue
|
|
36
|
+
q.name.should == 'test1'
|
|
37
|
+
@b.queues.has_key?('test1').should be true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# exchange_spec.rb
|
|
2
|
+
|
|
3
|
+
# Assumes that target message broker/server has a user called 'guest' with a password 'guest'
|
|
4
|
+
# and that it is running on 'localhost'.
|
|
5
|
+
|
|
6
|
+
# If this is not the case, please change the 'Bunny.new' call below to include
|
|
7
|
+
# the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
|
|
8
|
+
|
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
|
|
10
|
+
|
|
11
|
+
describe Exchange do
|
|
12
|
+
|
|
13
|
+
before(:each) do
|
|
14
|
+
@b = Bunny.new
|
|
15
|
+
@b.start
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
after(:each) do
|
|
19
|
+
@b.stop
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should be able to create a default direct exchange" do
|
|
23
|
+
exch = @b.exchange('direct_defaultex')
|
|
24
|
+
exch.should be_an_instance_of Exchange
|
|
25
|
+
exch.name.should == 'direct_defaultex'
|
|
26
|
+
exch.type.should == :direct
|
|
27
|
+
@b.exchanges.has_key?('direct_defaultex').should be true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should be able to be instantiated as a direct exchange" do
|
|
31
|
+
exch = @b.exchange('direct_exchange', :type => :direct)
|
|
32
|
+
exch.should be_an_instance_of Exchange
|
|
33
|
+
exch.name.should == 'direct_exchange'
|
|
34
|
+
exch.type.should == :direct
|
|
35
|
+
@b.exchanges.has_key?('direct_exchange').should be true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "should be able to be instantiated as a topic exchange" do
|
|
39
|
+
exch = @b.exchange('topic_exchange', :type => :topic)
|
|
40
|
+
exch.should be_an_instance_of Exchange
|
|
41
|
+
exch.name.should == 'topic_exchange'
|
|
42
|
+
exch.type.should == :topic
|
|
43
|
+
@b.exchanges.has_key?('topic_exchange').should be true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should be able to be instantiated as a fanout exchange" do
|
|
47
|
+
exch = @b.exchange('fanout_exchange', :type => :fanout)
|
|
48
|
+
exch.should be_an_instance_of Exchange
|
|
49
|
+
exch.name.should == 'fanout_exchange'
|
|
50
|
+
exch.type.should == :fanout
|
|
51
|
+
@b.exchanges.has_key?('fanout_exchange').should be true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should be able to publish a message" do
|
|
55
|
+
exch = @b.exchange('direct_exchange')
|
|
56
|
+
exch.publish('This is a published message')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should be able to be deleted" do
|
|
60
|
+
exch = @b.exchange('direct_exchange')
|
|
61
|
+
exch.delete
|
|
62
|
+
@b.exchanges.has_key?('direct_exchange').should be false
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
data/spec/queue_spec.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# queue_spec.rb
|
|
2
|
+
|
|
3
|
+
# Assumes that target message broker/server has a user called 'guest' with a password 'guest'
|
|
4
|
+
# and that it is running on 'localhost'.
|
|
5
|
+
|
|
6
|
+
# If this is not the case, please change the 'Bunny.new' call below to include
|
|
7
|
+
# the relevant arguments e.g. @b = Bunny.new(:user => 'john', :pass => 'doe', :host => 'foobar')
|
|
8
|
+
|
|
9
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
|
|
10
|
+
|
|
11
|
+
describe Bunny do
|
|
12
|
+
|
|
13
|
+
before(:each) do
|
|
14
|
+
@b = Bunny.new
|
|
15
|
+
@b.start
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
after(:each) do
|
|
19
|
+
@b.stop
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "should be able to publish a message" do
|
|
23
|
+
q = @b.queue('test1')
|
|
24
|
+
q.publish('This is a test message')
|
|
25
|
+
q.message_count.should == 1
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "should be able to pop a message complete with header" do
|
|
29
|
+
q = @b.queue('test1')
|
|
30
|
+
msg = q.pop(:header => true)
|
|
31
|
+
msg.should be_an_instance_of Hash
|
|
32
|
+
msg[:header].should be_an_instance_of AMQP::Protocol::Header
|
|
33
|
+
msg[:payload].should == 'This is a test message'
|
|
34
|
+
q.message_count.should == 0
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "should be able to pop a message and just get the payload" do
|
|
38
|
+
q = @b.queue('test1')
|
|
39
|
+
q.publish('This is another test message')
|
|
40
|
+
msg = q.pop
|
|
41
|
+
msg.should == 'This is another test message'
|
|
42
|
+
q.message_count.should == 0
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "should be able to be deleted" do
|
|
46
|
+
q = @b.queue('test1')
|
|
47
|
+
q.delete
|
|
48
|
+
@b.queues.has_key?('test1').should be false
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bunny
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.8
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chris Duncan
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-04-24 00:00:00 +01:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Another synchronous Ruby AMQP client
|
|
17
|
+
email: celldee@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- Rakefile
|
|
26
|
+
- README.markdown
|
|
27
|
+
- lib/amqp
|
|
28
|
+
- lib/amqp.rb
|
|
29
|
+
- lib/amqp/buffer.rb
|
|
30
|
+
- lib/bunny/exchange.rb
|
|
31
|
+
- lib/amqp/frame.rb
|
|
32
|
+
- lib/bunny/header.rb
|
|
33
|
+
- lib/amqp/protocol.rb
|
|
34
|
+
- lib/bunny/queue.rb
|
|
35
|
+
- lib/amqp/client.rb
|
|
36
|
+
- lib/amqp/spec.rb
|
|
37
|
+
- lib/bunny.rb
|
|
38
|
+
- examples/simple.rb
|
|
39
|
+
- spec/bunny_spec.rb
|
|
40
|
+
- spec/exchange_spec.rb
|
|
41
|
+
- spec/queue_spec.rb
|
|
42
|
+
- protocol/amqp-0.8.json
|
|
43
|
+
- protocol/amqp-0.8.xml
|
|
44
|
+
- protocol/codegen.rb
|
|
45
|
+
has_rdoc: true
|
|
46
|
+
homepage: http://github.com/celldee/bunny
|
|
47
|
+
post_install_message:
|
|
48
|
+
rdoc_options:
|
|
49
|
+
- --inline-source
|
|
50
|
+
- --charset=UTF-8
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: "0"
|
|
58
|
+
version:
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: "0"
|
|
64
|
+
version:
|
|
65
|
+
requirements: []
|
|
66
|
+
|
|
67
|
+
rubyforge_project:
|
|
68
|
+
rubygems_version: 1.3.1
|
|
69
|
+
signing_key:
|
|
70
|
+
specification_version: 2
|
|
71
|
+
summary: Another synchronous Ruby AMQP client
|
|
72
|
+
test_files: []
|
|
73
|
+
|