celldee-bunny 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/README.markdown +43 -0
- data/Rakefile +12 -0
- data/examples/simple.rb +30 -0
- data/lib/amqp/buffer.rb +276 -0
- data/lib/amqp/client.rb +160 -0
- data/lib/amqp/frame.rb +62 -0
- data/lib/amqp/protocol.rb +158 -0
- data/lib/amqp/spec.rb +832 -0
- data/lib/amqp.rb +5 -0
- data/lib/bunny/exchange.rb +49 -0
- data/lib/bunny/header.rb +30 -0
- data/lib/bunny/logger.rb +89 -0
- data/lib/bunny/queue.rb +93 -0
- data/lib/bunny.rb +57 -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 +55 -0
- metadata +72 -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,55 @@
|
|
|
1
|
+
# bunny_spec.rb
|
|
2
|
+
|
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib bunny]))
|
|
4
|
+
|
|
5
|
+
describe Bunny do
|
|
6
|
+
|
|
7
|
+
before(:each) do
|
|
8
|
+
@b = Bunny.new
|
|
9
|
+
@b.start
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "should connect to an AMQP server" do
|
|
13
|
+
@b.status.should == 'CONNECTED'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should be able to create an exchange" do
|
|
17
|
+
exch = Exchange.new(@b.client, :direct, 'test_exchange')
|
|
18
|
+
exch.should be_an_instance_of Exchange
|
|
19
|
+
exch.name.should == 'test_exchange'
|
|
20
|
+
@b.exchanges.has_key?('test_exchange').should be true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should be able to delete an exchange" do
|
|
24
|
+
exch = Exchange.new(@b.client, :direct, 'test_exchange')
|
|
25
|
+
exch.delete
|
|
26
|
+
@b.exchanges.has_key?('test_exchange').should be false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should be able to create a queue" do
|
|
30
|
+
q = @b.queue('test1')
|
|
31
|
+
q.should be_an_instance_of Queue
|
|
32
|
+
q.name.should == 'test1'
|
|
33
|
+
@b.queues.has_key?('test1').should be true
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "should be able to publish a message to a queue" do
|
|
37
|
+
q = @b.queue('test1')
|
|
38
|
+
q.publish('This is a test message')
|
|
39
|
+
q.message_count.should == 1
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "should be able to get a message from a queue" do
|
|
43
|
+
q = @b.queue('test1')
|
|
44
|
+
msg = q.pop
|
|
45
|
+
msg.should == 'This is a test message'
|
|
46
|
+
q.message_count.should == 0
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should be able to delete a queue" do
|
|
50
|
+
q = @b.queue('test1')
|
|
51
|
+
q.delete
|
|
52
|
+
@b.queues.has_key?('test1').should be true
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: celldee-bunny
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Chris Duncan
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-04-20 00:00:00 -07: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/bunny/logger.rb
|
|
34
|
+
- lib/amqp/protocol.rb
|
|
35
|
+
- lib/bunny/queue.rb
|
|
36
|
+
- lib/amqp/client.rb
|
|
37
|
+
- lib/amqp/spec.rb
|
|
38
|
+
- lib/bunny.rb
|
|
39
|
+
- examples/simple.rb
|
|
40
|
+
- spec/bunny_spec.rb
|
|
41
|
+
- protocol/amqp-0.8.json
|
|
42
|
+
- protocol/amqp-0.8.xml
|
|
43
|
+
- protocol/codegen.rb
|
|
44
|
+
has_rdoc: true
|
|
45
|
+
homepage: http://github.com/celldee/bunny
|
|
46
|
+
post_install_message:
|
|
47
|
+
rdoc_options:
|
|
48
|
+
- --inline-source
|
|
49
|
+
- --charset=UTF-8
|
|
50
|
+
require_paths:
|
|
51
|
+
- lib
|
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: "0"
|
|
57
|
+
version:
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: "0"
|
|
63
|
+
version:
|
|
64
|
+
requirements: []
|
|
65
|
+
|
|
66
|
+
rubyforge_project:
|
|
67
|
+
rubygems_version: 1.2.0
|
|
68
|
+
signing_key:
|
|
69
|
+
specification_version: 2
|
|
70
|
+
summary: TODO
|
|
71
|
+
test_files: []
|
|
72
|
+
|