amqp 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,165 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+
4
+ s = JSON.parse(File.read(File.dirname(__FILE__)+'/amqp-0.8.json'))
5
+
6
+ # require 'pp'
7
+ # pp(s)
8
+ # exit
9
+
10
+ require 'erb'
11
+
12
+ puts ERB.new(%q[
13
+ module AMQP
14
+ HEADER = <%= s['name'].dump %>.freeze
15
+ VERSION_MAJOR = <%= s['major-version'] %>
16
+ VERSION_MINOR = <%= s['minor-version'] %>
17
+ PORT = <%= s['port'] %>
18
+
19
+ class Frame
20
+ def self.types
21
+ @types ||= {}
22
+ end
23
+
24
+ def self.Frame id
25
+ (@_base_frames ||= {})[id] ||= Class.new(Frame) do
26
+ class_eval %[
27
+ def self.inherited klass
28
+ klass.const_set(:ID, #{id})
29
+ Frame.types[#{id}] = klass
30
+ end
31
+ ]
32
+ end
33
+ end
34
+
35
+ <%- s['constants'].select{|c| (1..8).include? c['value'] }.each do |c| -%>
36
+ class <%= c['name'].gsub(/^FRAME-/,'').split('-').map{|w| w.downcase.capitalize}.join.ljust(9) -%> < Frame( <%= c['value'] -%> ); end
37
+ <%- end -%>
38
+
39
+ FOOTER = <%= frame_end = s['constants'].find{|c| c['name'] == 'FRAME-END' }['value'] %>
40
+ end
41
+
42
+ RESPONSES = {
43
+ <%- s['constants'].select{|c| c['value'] != frame_end and (200..500).include? c['value'] }.each do |c| -%>
44
+ <%= c['value'] %> => :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
45
+ <%- end -%>
46
+ }
47
+
48
+ FIELDS = [
49
+ <%- s['domains'].select{|d| d.first == d.last }.each do |d| -%>
50
+ :<%= d.first -%>,
51
+ <%- end -%>
52
+ ]
53
+
54
+ module Protocol
55
+ class Class
56
+ class << self
57
+ FIELDS.each do |f|
58
+ class_eval %[
59
+ def #{f} name
60
+ properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
61
+ attr_accessor name
62
+ end
63
+ ]
64
+ end
65
+
66
+ def properties() @properties ||= [] end
67
+
68
+ def id() self::ID end
69
+ def name() self::NAME end
70
+ end
71
+
72
+ class Method
73
+ class << self
74
+ FIELDS.each do |f|
75
+ class_eval %[
76
+ def #{f} name
77
+ arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
78
+ attr_accessor name
79
+ end
80
+ ]
81
+ end
82
+
83
+ def arguments() @arguments ||= [] end
84
+
85
+ def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
86
+ def id() self::ID end
87
+ def name() self::NAME end
88
+ end
89
+
90
+ def == b
91
+ self.class.arguments.inject(true) do |eql, (type, name)|
92
+ eql and __send__("#{name}") == b.__send__("#{name}")
93
+ end
94
+ end
95
+ end
96
+
97
+ def self.methods() @methods ||= {} end
98
+
99
+ def self.Method(id, name)
100
+ @_base_methods ||= {}
101
+ @_base_methods[id] ||= ::Class.new(Method) do
102
+ class_eval %[
103
+ def self.inherited klass
104
+ klass.const_set(:ID, #{id})
105
+ klass.const_set(:NAME, :#{name.to_s})
106
+ klass.parent.methods[#{id}] = klass
107
+ klass.parent.methods[klass::NAME] = klass
108
+ end
109
+ ]
110
+ end
111
+ end
112
+ end
113
+
114
+ def self.classes() @classes ||= {} end
115
+
116
+ def self.Class(id, name)
117
+ @_base_classes ||= {}
118
+ @_base_classes[id] ||= ::Class.new(Class) do
119
+ class_eval %[
120
+ def self.inherited klass
121
+ klass.const_set(:ID, #{id})
122
+ klass.const_set(:NAME, :#{name.to_s})
123
+ Protocol.classes[#{id}] = klass
124
+ Protocol.classes[klass::NAME] = klass
125
+ end
126
+ ]
127
+ end
128
+ end
129
+ end
130
+ end
131
+
132
+ module AMQP
133
+ module Protocol
134
+ <%- s['classes'].each do |c| -%>
135
+ class <%= c['name'].capitalize.ljust(12) %> < Class( <%= c['id'].to_s.rjust(3) %>, :<%= c['name'].ljust(12) %> ); end
136
+ <%- end -%>
137
+
138
+ <%- s['classes'].each do |c| -%>
139
+ class <%= c['name'].capitalize %>
140
+ <%- c['properties'].each do |p| -%>
141
+ <%= p['type'].ljust(10) %> :<%= p['name'].tr('-','_') %>
142
+ <%- end if c['properties'] -%>
143
+
144
+ <%- c['methods'].each do |m| -%>
145
+ class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"}.ljust(12) %> < Method( <%= m['id'].to_s.rjust(3) %>, :<%= m['name'].tr('- ','_').ljust(14) %> ); end
146
+ <%- end -%>
147
+
148
+ <%- c['methods'].each do |m| -%>
149
+ class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"} %>
150
+ <%- m['arguments'].each do |a| -%>
151
+ <%- if a['domain'] -%>
152
+ <%= s['domains'].find{|k,v| k == a['domain']}.last.ljust(10) %> :<%= a['name'].tr('- ','_') %>
153
+ <%- else -%>
154
+ <%= a['type'].ljust(10) %> :<%= a['name'].tr('- ','_') %>
155
+ <%- end -%>
156
+ <%- end if m['arguments'] -%>
157
+ end
158
+
159
+ <%- end -%>
160
+ end
161
+
162
+ <%- end -%>
163
+ end
164
+ end
165
+ ].gsub!(/^ /,''), nil, '>-%').result(binding)
@@ -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"]
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amqp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Aman Gupta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-17 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: AMQP client implementation in Ruby/EventMachine
17
+ email: amqp@tmm1.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - examples/clock.rb
26
+ - examples/hashtable.rb
27
+ - examples/pingpong.rb
28
+ - examples/simple.rb
29
+ - examples/stocks.rb
30
+ - lib/amqp/buffer.rb
31
+ - lib/amqp/client.rb
32
+ - lib/amqp/frame.rb
33
+ - lib/amqp/protocol.rb
34
+ - lib/amqp/spec.rb
35
+ - lib/amqp.rb
36
+ - lib/mq.rb
37
+ - protocol/amqp-0.8.json
38
+ - protocol/codegen.rb
39
+ - protocol/doc.txt
40
+ - protocol/amqp-0.8.xml
41
+ - README
42
+ has_rdoc: false
43
+ homepage: http://amqp.rubyforge.org/
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: AMQP client implementation in Ruby/EventMachine
68
+ test_files: []
69
+