famoseagle-carrot 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/LICENSE +20 -0
- data/README.markdown +15 -5
- data/Rakefile +40 -0
- data/VERSION.yml +2 -2
- data/carrot.gemspec +58 -0
- data/lib/amqp/queue.rb +5 -2
- data/lib/amqp/server.rb +1 -0
- data/protocol/amqp-0.8.json +617 -0
- data/protocol/amqp-0.8.xml +3908 -0
- data/protocol/codegen.rb +173 -0
- data/protocol/doc.txt +281 -0
- data/test/carrot_test.rb +7 -0
- metadata +18 -10
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/protocol/doc.txt
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
["connected"]
|
2
|
+
|
3
|
+
["send_data", "AMQP"]
|
4
|
+
|
5
|
+
["send_data", "\001\001\b\000"]
|
6
|
+
|
7
|
+
["receive_data",
|
8
|
+
"\001\000\000\000\000\001&\000\n\000\n\b\000\000\000\001\001\aproductS\000\000\000\bRabbitMQ\aversionS\000\000\000\v%%VERSION%%\bplatformS\000\000\000\nErlang/OTP\tcopyrightS\000\000\000gCopyright (C) 2007-2008 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.\vinformationS\000\000\0005Licensed under the MPL. See http://www.rabbitmq.com/\000\000\000\016PLAIN AMQPLAIN\000\000\000\005en_US\316"]
|
9
|
+
|
10
|
+
["receive",
|
11
|
+
#<AMQP::Frame::Method:0x11b90d0
|
12
|
+
@channel=0,
|
13
|
+
@payload=
|
14
|
+
#<AMQP::Protocol::Connection::Start:0x11b8d38
|
15
|
+
@debug=1,
|
16
|
+
@locales="en_US",
|
17
|
+
@mechanisms="PLAIN AMQPLAIN",
|
18
|
+
@server_properties=
|
19
|
+
{:information=>"Licensed under the MPL. See http://www.rabbitmq.com/",
|
20
|
+
:copyright=>
|
21
|
+
"Copyright (C) 2007-2008 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.",
|
22
|
+
:platform=>"Erlang/OTP",
|
23
|
+
:version=>"%%VERSION%%",
|
24
|
+
:product=>"RabbitMQ"},
|
25
|
+
@version_major=8,
|
26
|
+
@version_minor=0>>]
|
27
|
+
|
28
|
+
["send",
|
29
|
+
#<AMQP::Frame::Method:0x11a3078
|
30
|
+
@channel=0,
|
31
|
+
@payload=
|
32
|
+
#<AMQP::Protocol::Connection::StartOk:0x11a3294
|
33
|
+
@client_properties=
|
34
|
+
{:information=>"http://github.com/tmm1/amqp",
|
35
|
+
:version=>"0.1.0",
|
36
|
+
:product=>"AMQP",
|
37
|
+
:platform=>"Ruby/EventMachine"},
|
38
|
+
@debug=1,
|
39
|
+
@locale="en_US",
|
40
|
+
@mechanism="AMQPLAIN",
|
41
|
+
@response={:LOGIN=>"guest", :PASSWORD=>"guest"}>>]
|
42
|
+
|
43
|
+
["send_data",
|
44
|
+
"\001\000\000\000\000\000\254\000\n\000\v\000\000\000n\vinformationS\000\000\000\ehttp://github.com/tmm1/amqp\aversionS\000\000\000\0050.1.0\aproductS\000\000\000\004AMQP\bplatformS\000\000\000\021Ruby/EventMachine\bAMQPLAIN\000\000\000#\005LOGINS\000\000\000\005guest\bPASSWORDS\000\000\000\005guest\005en_US\316"]
|
45
|
+
|
46
|
+
["receive_data",
|
47
|
+
"\001\000\000\000\000\000\f\000\n\000\036\000\000\000\002\000\000\000\000\316"]
|
48
|
+
|
49
|
+
["receive",
|
50
|
+
#<AMQP::Frame::Method:0x11898e4
|
51
|
+
@channel=0,
|
52
|
+
@payload=
|
53
|
+
#<AMQP::Protocol::Connection::Tune:0x118954c
|
54
|
+
@channel_max=0,
|
55
|
+
@debug=1,
|
56
|
+
@frame_max=131072,
|
57
|
+
@heartbeat=0>>]
|
58
|
+
|
59
|
+
["send",
|
60
|
+
#<AMQP::Frame::Method:0x117fb14
|
61
|
+
@channel=0,
|
62
|
+
@payload=
|
63
|
+
#<AMQP::Protocol::Connection::TuneOk:0x117fd1c
|
64
|
+
@channel_max=0,
|
65
|
+
@debug=1,
|
66
|
+
@frame_max=131072,
|
67
|
+
@heartbeat=0>>]
|
68
|
+
|
69
|
+
["send_data",
|
70
|
+
"\001\000\000\000\000\000\f\000\n\000\037\000\000\000\002\000\000\000\000\316"]
|
71
|
+
|
72
|
+
["send",
|
73
|
+
#<AMQP::Frame::Method:0x11741d8
|
74
|
+
@channel=0,
|
75
|
+
@payload=
|
76
|
+
#<AMQP::Protocol::Connection::Open:0x1174408
|
77
|
+
@capabilities="",
|
78
|
+
@debug=1,
|
79
|
+
@insist=nil,
|
80
|
+
@virtual_host="/">>]
|
81
|
+
|
82
|
+
["send_data", "\001\000\000\000\000\000\b\000\n\000(\001/\000\000\316"]
|
83
|
+
|
84
|
+
["receive_data",
|
85
|
+
"\001\000\000\000\000\000\025\000\n\000)\020julie.local:5672\316"]
|
86
|
+
|
87
|
+
["receive",
|
88
|
+
#<AMQP::Frame::Method:0x11665ec
|
89
|
+
@channel=0,
|
90
|
+
@payload=
|
91
|
+
#<AMQP::Protocol::Connection::OpenOk:0x1166254
|
92
|
+
@debug=1,
|
93
|
+
@known_hosts="julie.local:5672">>]
|
94
|
+
|
95
|
+
["send",
|
96
|
+
#<AMQP::Frame::Method:0x115e950
|
97
|
+
@channel=1,
|
98
|
+
@payload=
|
99
|
+
#<AMQP::Protocol::Channel::Open:0x115ebf8 @debug=1, @out_of_band=nil>>]
|
100
|
+
|
101
|
+
["send_data", "\001\000\001\000\000\000\005\000\024\000\n\000\316"]
|
102
|
+
|
103
|
+
["receive_data", "\001\000\001\000\000\000\004\000\024\000\v\316"]
|
104
|
+
|
105
|
+
["receive",
|
106
|
+
#<AMQP::Frame::Method:0x11534d8
|
107
|
+
@channel=1,
|
108
|
+
@payload=#<AMQP::Protocol::Channel::OpenOk:0x1153140 @debug=1>>]
|
109
|
+
|
110
|
+
["send",
|
111
|
+
#<AMQP::Frame::Method:0x114d0ec
|
112
|
+
@channel=1,
|
113
|
+
@payload=
|
114
|
+
#<AMQP::Protocol::Access::Request:0x114d434
|
115
|
+
@active=true,
|
116
|
+
@debug=1,
|
117
|
+
@exclusive=nil,
|
118
|
+
@passive=nil,
|
119
|
+
@read=true,
|
120
|
+
@realm="/data",
|
121
|
+
@write=true>>]
|
122
|
+
|
123
|
+
["send_data", "\001\000\001\000\000\000\v\000\036\000\n\005/data\034\316"]
|
124
|
+
|
125
|
+
["receive_data", "\001\000\001\000\000\000\006\000\036\000\v\000e\316"]
|
126
|
+
|
127
|
+
["receive",
|
128
|
+
#<AMQP::Frame::Method:0x113c9a4
|
129
|
+
@channel=1,
|
130
|
+
@payload=
|
131
|
+
#<AMQP::Protocol::Access::RequestOk:0x113c60c @debug=1, @ticket=101>>]
|
132
|
+
|
133
|
+
["send",
|
134
|
+
#<AMQP::Frame::Method:0x1135000
|
135
|
+
@channel=1,
|
136
|
+
@payload=
|
137
|
+
#<AMQP::Protocol::Queue::Declare:0x1135460
|
138
|
+
@arguments=nil,
|
139
|
+
@auto_delete=true,
|
140
|
+
@debug=1,
|
141
|
+
@durable=nil,
|
142
|
+
@exclusive=nil,
|
143
|
+
@nowait=nil,
|
144
|
+
@passive=nil,
|
145
|
+
@queue="",
|
146
|
+
@ticket=101>>]
|
147
|
+
|
148
|
+
["send_data",
|
149
|
+
"\001\000\001\000\000\000\f\0002\000\n\000e\000\b\000\000\000\000\316"]
|
150
|
+
|
151
|
+
["receive_data",
|
152
|
+
"\001\000\001\000\000\000-\0002\000\v amq.gen-RCSkW3cCvMc1I0wXBcLYSg==\000\000\000\000\000\000\000\000\316"]
|
153
|
+
|
154
|
+
["receive",
|
155
|
+
#<AMQP::Frame::Method:0x1122838
|
156
|
+
@channel=1,
|
157
|
+
@payload=
|
158
|
+
#<AMQP::Protocol::Queue::DeclareOk:0x11224a0
|
159
|
+
@consumer_count=0,
|
160
|
+
@debug=1,
|
161
|
+
@message_count=0,
|
162
|
+
@queue="amq.gen-RCSkW3cCvMc1I0wXBcLYSg==">>]
|
163
|
+
|
164
|
+
["send",
|
165
|
+
#<AMQP::Frame::Method:0x1118860
|
166
|
+
@channel=1,
|
167
|
+
@payload=
|
168
|
+
#<AMQP::Protocol::Queue::Bind:0x1118ba8
|
169
|
+
@arguments=nil,
|
170
|
+
@debug=1,
|
171
|
+
@exchange="",
|
172
|
+
@nowait=nil,
|
173
|
+
@queue="amq.gen-RCSkW3cCvMc1I0wXBcLYSg==",
|
174
|
+
@routing_key="test_route",
|
175
|
+
@ticket=101>>]
|
176
|
+
|
177
|
+
["send_data",
|
178
|
+
"\001\000\001\000\000\0008\0002\000\024\000e amq.gen-RCSkW3cCvMc1I0wXBcLYSg==\000\ntest_route\000\000\000\000\000\316"]
|
179
|
+
|
180
|
+
["receive_data", "\001\000\001\000\000\000\004\0002\000\025\316"]
|
181
|
+
|
182
|
+
["receive",
|
183
|
+
#<AMQP::Frame::Method:0x1107a4c
|
184
|
+
@channel=1,
|
185
|
+
@payload=#<AMQP::Protocol::Queue::BindOk:0x11076b4 @debug=1>>]
|
186
|
+
|
187
|
+
["send",
|
188
|
+
#<AMQP::Frame::Method:0x11015d4
|
189
|
+
@channel=1,
|
190
|
+
@payload=
|
191
|
+
#<AMQP::Protocol::Basic::Consume:0x11019bc
|
192
|
+
@consumer_tag=nil,
|
193
|
+
@debug=1,
|
194
|
+
@exclusive=nil,
|
195
|
+
@no_ack=true,
|
196
|
+
@no_local=nil,
|
197
|
+
@nowait=nil,
|
198
|
+
@queue="amq.gen-RCSkW3cCvMc1I0wXBcLYSg==",
|
199
|
+
@ticket=101>>]
|
200
|
+
|
201
|
+
["send_data",
|
202
|
+
"\001\000\001\000\000\000)\000<\000\024\000e amq.gen-RCSkW3cCvMc1I0wXBcLYSg==\000\002\316"]
|
203
|
+
|
204
|
+
["receive_data",
|
205
|
+
"\001\000\001\000\000\000&\000<\000\025!amq.ctag-wFbDeuYKGEm7tXh8oaE5Qg==\316"]
|
206
|
+
|
207
|
+
["receive",
|
208
|
+
#<AMQP::Frame::Method:0x5f6cfc
|
209
|
+
@channel=1,
|
210
|
+
@payload=
|
211
|
+
#<AMQP::Protocol::Basic::ConsumeOk:0x5f67e8
|
212
|
+
@consumer_tag="amq.ctag-wFbDeuYKGEm7tXh8oaE5Qg==",
|
213
|
+
@debug=1>>]
|
214
|
+
|
215
|
+
["send",
|
216
|
+
#<AMQP::Frame::Method:0x5e3dc8
|
217
|
+
@channel=1,
|
218
|
+
@payload=
|
219
|
+
#<AMQP::Protocol::Basic::Publish:0x5e4264
|
220
|
+
@debug=1,
|
221
|
+
@exchange="",
|
222
|
+
@immediate=nil,
|
223
|
+
@mandatory=nil,
|
224
|
+
@routing_key="test_route",
|
225
|
+
@ticket=101>>]
|
226
|
+
|
227
|
+
["send_data",
|
228
|
+
"\001\000\001\000\000\000\023\000<\000(\000e\000\ntest_route\000\316"]
|
229
|
+
|
230
|
+
["send",
|
231
|
+
#<AMQP::Frame::Header:0x5bc994
|
232
|
+
@channel=1,
|
233
|
+
@payload=
|
234
|
+
#<AMQP::Protocol::Header:0x5bcb88
|
235
|
+
@klass=AMQP::Protocol::Basic,
|
236
|
+
@properties=
|
237
|
+
{:delivery_mode=>1,
|
238
|
+
:priority=>1,
|
239
|
+
:content_type=>"application/octet-stream"},
|
240
|
+
@size=15,
|
241
|
+
@weight=0>>]
|
242
|
+
|
243
|
+
["send_data",
|
244
|
+
"\002\000\001\000\000\000)\000<\000\000\000\000\000\000\000\000\000\017\230\000\030application/octet-stream\001\001\316"]
|
245
|
+
|
246
|
+
["send", #<AMQP::Frame::Body:0x57cfc4 @channel=1, @payload="this is a test!">]
|
247
|
+
|
248
|
+
["send_data", "\003\000\001\000\000\000\017this is a test!\316"]
|
249
|
+
|
250
|
+
["receive_data",
|
251
|
+
"\001\000\001\000\000\000;\000<\000<!amq.ctag-wFbDeuYKGEm7tXh8oaE5Qg==\000\000\000\000\000\000\000\001\000\000\ntest_route\316\002\000\001\000\000\000)\000<\000\000\000\000\000\000\000\000\000\017\230\000\030application/octet-stream\001\001\316\003\000\001\000\000\000\017this is a test!\316"]
|
252
|
+
|
253
|
+
["receive",
|
254
|
+
#<AMQP::Frame::Method:0x55cbe8
|
255
|
+
@channel=1,
|
256
|
+
@payload=
|
257
|
+
#<AMQP::Protocol::Basic::Deliver:0x55b810
|
258
|
+
@consumer_tag="amq.ctag-wFbDeuYKGEm7tXh8oaE5Qg==",
|
259
|
+
@debug=1,
|
260
|
+
@delivery_tag=1,
|
261
|
+
@exchange="",
|
262
|
+
@redelivered=false,
|
263
|
+
@routing_key="test_route">>]
|
264
|
+
|
265
|
+
["receive",
|
266
|
+
#<AMQP::Frame::Header:0x537af0
|
267
|
+
@channel=1,
|
268
|
+
@payload=
|
269
|
+
#<AMQP::Protocol::Header:0x537a28
|
270
|
+
@klass=AMQP::Protocol::Basic,
|
271
|
+
@properties=
|
272
|
+
{:delivery_mode=>1,
|
273
|
+
:priority=>1,
|
274
|
+
:content_type=>"application/octet-stream"},
|
275
|
+
@size=15,
|
276
|
+
@weight=0>>]
|
277
|
+
|
278
|
+
["receive",
|
279
|
+
#<AMQP::Frame::Body:0x505f64 @channel=1, @payload="this is a test!">]
|
280
|
+
|
281
|
+
^C["disconnected"]
|