tmm1-amqp 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,172 @@
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
+ # this file was autogenerated on <%= Time.now.to_s %>
16
+ # using <%= name.ljust(16) %> (mtime: <%= File.mtime(path) %>)
17
+ #
18
+ # DO NOT EDIT! (edit protocol/codegen.rb instead, and run `rake codegen`)
19
+
20
+ module AMQP
21
+ HEADER = <%= s['name'].dump %>.freeze
22
+ VERSION_MAJOR = <%= s['major-version'] %>
23
+ VERSION_MINOR = <%= s['minor-version'] %>
24
+ PORT = <%= s['port'] %>
25
+
26
+ class Frame
27
+ def self.types
28
+ @types ||= {}
29
+ end
30
+
31
+ def self.Frame id
32
+ (@_base_frames ||= {})[id] ||= Class.new(Frame) do
33
+ class_eval %[
34
+ def self.inherited klass
35
+ klass.const_set(:ID, #{id})
36
+ Frame.types[#{id}] = klass
37
+ end
38
+ ]
39
+ end
40
+ end
41
+
42
+ <%- s['constants'].select{|c| (1..8).include? c['value'] }.each do |c| -%>
43
+ class <%= c['name'].gsub(/^FRAME-/,'').split('-').map{|w| w.downcase.capitalize}.join.ljust(9) -%> < Frame( <%= c['value'] -%> ); end
44
+ <%- end -%>
45
+
46
+ FOOTER = <%= frame_end = s['constants'].find{|c| c['name'] == 'FRAME-END' }['value'] %>
47
+ end
48
+
49
+ RESPONSES = {
50
+ <%- s['constants'].select{|c| c['value'] != frame_end and (200..500).include? c['value'] }.each do |c| -%>
51
+ <%= c['value'] %> => :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
52
+ <%- end -%>
53
+ }
54
+
55
+ FIELDS = [
56
+ <%- s['domains'].select{|d| d.first == d.last }.each do |d| -%>
57
+ :<%= d.first -%>,
58
+ <%- end -%>
59
+ ]
60
+
61
+ module Protocol
62
+ class Class
63
+ class << self
64
+ FIELDS.each do |f|
65
+ class_eval %[
66
+ def #{f} name
67
+ properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
68
+ attr_accessor name
69
+ end
70
+ ]
71
+ end
72
+
73
+ def properties() @properties ||= [] end
74
+
75
+ def id() self::ID end
76
+ def name() self::NAME end
77
+ end
78
+
79
+ class Method
80
+ class << self
81
+ FIELDS.each do |f|
82
+ class_eval %[
83
+ def #{f} name
84
+ arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
85
+ attr_accessor name
86
+ end
87
+ ]
88
+ end
89
+
90
+ def arguments() @arguments ||= [] end
91
+
92
+ def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
93
+ def id() self::ID end
94
+ def name() self::NAME end
95
+ end
96
+
97
+ def == b
98
+ self.class.arguments.inject(true) do |eql, (type, name)|
99
+ eql and __send__("#{name}") == b.__send__("#{name}")
100
+ end
101
+ end
102
+ end
103
+
104
+ def self.methods() @methods ||= {} end
105
+
106
+ def self.Method(id, name)
107
+ @_base_methods ||= {}
108
+ @_base_methods[id] ||= ::Class.new(Method) do
109
+ class_eval %[
110
+ def self.inherited klass
111
+ klass.const_set(:ID, #{id})
112
+ klass.const_set(:NAME, :#{name.to_s})
113
+ klass.parent.methods[#{id}] = klass
114
+ klass.parent.methods[klass::NAME] = klass
115
+ end
116
+ ]
117
+ end
118
+ end
119
+ end
120
+
121
+ def self.classes() @classes ||= {} end
122
+
123
+ def self.Class(id, name)
124
+ @_base_classes ||= {}
125
+ @_base_classes[id] ||= ::Class.new(Class) do
126
+ class_eval %[
127
+ def self.inherited klass
128
+ klass.const_set(:ID, #{id})
129
+ klass.const_set(:NAME, :#{name.to_s})
130
+ Protocol.classes[#{id}] = klass
131
+ Protocol.classes[klass::NAME] = klass
132
+ end
133
+ ]
134
+ end
135
+ end
136
+ end
137
+ end
138
+
139
+ module AMQP
140
+ module Protocol
141
+ <%- s['classes'].each do |c| -%>
142
+ class <%= c['name'].capitalize.ljust(12) %> < Class( <%= c['id'].to_s.rjust(3) %>, :<%= c['name'].ljust(12) %> ); end
143
+ <%- end -%>
144
+
145
+ <%- s['classes'].each do |c| -%>
146
+ class <%= c['name'].capitalize %>
147
+ <%- c['properties'].each do |p| -%>
148
+ <%= p['type'].ljust(10) %> :<%= p['name'].tr('-','_') %>
149
+ <%- end if c['properties'] -%>
150
+
151
+ <%- c['methods'].each do |m| -%>
152
+ class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"}.ljust(12) %> < Method( <%= m['id'].to_s.rjust(3) %>, :<%= m['name'].tr('- ','_').ljust(14) %> ); end
153
+ <%- end -%>
154
+
155
+ <%- c['methods'].each do |m| -%>
156
+ class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"} %>
157
+ <%- m['arguments'].each do |a| -%>
158
+ <%- if a['domain'] -%>
159
+ <%= s['domains'].find{|k,v| k == a['domain']}.last.ljust(10) %> :<%= a['name'].tr('- ','_') %>
160
+ <%- else -%>
161
+ <%= a['type'].ljust(10) %> :<%= a['name'].tr('- ','_') %>
162
+ <%- end -%>
163
+ <%- end if m['arguments'] -%>
164
+ end
165
+
166
+ <%- end -%>
167
+ end
168
+
169
+ <%- end -%>
170
+ end
171
+ end
172
+ ].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"]