bunny 0.8.0 → 0.9.0.pre1

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.
Files changed (91) hide show
  1. data/.gitignore +7 -1
  2. data/.travis.yml +14 -4
  3. data/ChangeLog.md +72 -0
  4. data/Gemfile +17 -11
  5. data/README.md +82 -0
  6. data/bunny.gemspec +6 -13
  7. data/examples/connection/heartbeat.rb +17 -0
  8. data/lib/bunny.rb +40 -56
  9. data/lib/bunny/channel.rb +615 -19
  10. data/lib/bunny/channel_id_allocator.rb +59 -0
  11. data/lib/bunny/compatibility.rb +24 -0
  12. data/lib/bunny/concurrent/condition.rb +63 -0
  13. data/lib/bunny/consumer.rb +42 -26
  14. data/lib/bunny/consumer_tag_generator.rb +22 -0
  15. data/lib/bunny/consumer_work_pool.rb +67 -0
  16. data/lib/bunny/exceptions.rb +128 -0
  17. data/lib/bunny/exchange.rb +131 -136
  18. data/lib/bunny/framing.rb +53 -0
  19. data/lib/bunny/heartbeat_sender.rb +59 -0
  20. data/lib/bunny/main_loop.rb +70 -0
  21. data/lib/bunny/message_metadata.rb +126 -0
  22. data/lib/bunny/queue.rb +102 -275
  23. data/lib/bunny/session.rb +478 -0
  24. data/lib/bunny/socket.rb +44 -0
  25. data/lib/bunny/system_timer.rb +9 -9
  26. data/lib/bunny/transport.rb +179 -0
  27. data/lib/bunny/version.rb +1 -1
  28. data/spec/compatibility/queue_declare_spec.rb +40 -0
  29. data/spec/higher_level_api/integration/basic_ack_spec.rb +54 -0
  30. data/spec/higher_level_api/integration/basic_consume_spec.rb +51 -0
  31. data/spec/higher_level_api/integration/basic_get_spec.rb +47 -0
  32. data/spec/higher_level_api/integration/basic_nack_spec.rb +39 -0
  33. data/spec/higher_level_api/integration/basic_publish_spec.rb +105 -0
  34. data/spec/higher_level_api/integration/basic_qos_spec.rb +32 -0
  35. data/spec/higher_level_api/integration/basic_recover_spec.rb +18 -0
  36. data/spec/higher_level_api/integration/basic_reject_spec.rb +53 -0
  37. data/spec/higher_level_api/integration/basic_return_spec.rb +33 -0
  38. data/spec/higher_level_api/integration/channel_close_spec.rb +29 -0
  39. data/spec/higher_level_api/integration/channel_flow_spec.rb +24 -0
  40. data/spec/higher_level_api/integration/channel_open_spec.rb +57 -0
  41. data/spec/higher_level_api/integration/channel_open_stress_spec.rb +22 -0
  42. data/spec/higher_level_api/integration/confirm_select_spec.rb +19 -0
  43. data/spec/higher_level_api/integration/connection_spec.rb +340 -0
  44. data/spec/higher_level_api/integration/exchange_bind_spec.rb +31 -0
  45. data/spec/higher_level_api/integration/exchange_declare_spec.rb +183 -0
  46. data/spec/higher_level_api/integration/exchange_delete_spec.rb +37 -0
  47. data/spec/higher_level_api/integration/exchange_unbind_spec.rb +40 -0
  48. data/spec/higher_level_api/integration/queue_bind_spec.rb +109 -0
  49. data/spec/higher_level_api/integration/queue_declare_spec.rb +129 -0
  50. data/spec/higher_level_api/integration/queue_delete_spec.rb +38 -0
  51. data/spec/higher_level_api/integration/queue_purge_spec.rb +30 -0
  52. data/spec/higher_level_api/integration/queue_unbind_spec.rb +33 -0
  53. data/spec/higher_level_api/integration/tx_commit_spec.rb +21 -0
  54. data/spec/higher_level_api/integration/tx_rollback_spec.rb +21 -0
  55. data/spec/lower_level_api/integration/basic_cancel_spec.rb +57 -0
  56. data/spec/lower_level_api/integration/basic_consume_spec.rb +100 -0
  57. data/spec/spec_helper.rb +64 -0
  58. data/spec/unit/bunny_spec.rb +15 -0
  59. data/spec/unit/concurrent/condition_spec.rb +66 -0
  60. metadata +135 -93
  61. data/CHANGELOG +0 -21
  62. data/README.textile +0 -76
  63. data/Rakefile +0 -14
  64. data/examples/simple.rb +0 -32
  65. data/examples/simple_ack.rb +0 -35
  66. data/examples/simple_consumer.rb +0 -55
  67. data/examples/simple_fanout.rb +0 -41
  68. data/examples/simple_headers.rb +0 -42
  69. data/examples/simple_publisher.rb +0 -29
  70. data/examples/simple_topic.rb +0 -61
  71. data/ext/amqp-0.9.1.json +0 -389
  72. data/ext/config.yml +0 -4
  73. data/ext/qparser.rb +0 -426
  74. data/lib/bunny/client.rb +0 -370
  75. data/lib/bunny/subscription.rb +0 -92
  76. data/lib/qrack/amq-client-url.rb +0 -165
  77. data/lib/qrack/channel.rb +0 -20
  78. data/lib/qrack/client.rb +0 -247
  79. data/lib/qrack/errors.rb +0 -5
  80. data/lib/qrack/protocol/protocol.rb +0 -135
  81. data/lib/qrack/protocol/spec.rb +0 -525
  82. data/lib/qrack/qrack.rb +0 -20
  83. data/lib/qrack/queue.rb +0 -40
  84. data/lib/qrack/subscription.rb +0 -152
  85. data/lib/qrack/transport/buffer.rb +0 -305
  86. data/lib/qrack/transport/frame.rb +0 -102
  87. data/spec/spec_09/amqp_url_spec.rb +0 -19
  88. data/spec/spec_09/bunny_spec.rb +0 -76
  89. data/spec/spec_09/connection_spec.rb +0 -34
  90. data/spec/spec_09/exchange_spec.rb +0 -173
  91. data/spec/spec_09/queue_spec.rb +0 -240
@@ -1,5 +0,0 @@
1
- module Qrack
2
- # Errors
3
- class BufferOverflowError < StandardError; end
4
- class InvalidTypeError < StandardError; end
5
- end
@@ -1,135 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Qrack
4
- module Protocol
5
- #:stopdoc:
6
- class Class::Method
7
- def initialize *args
8
- opts = args.pop if args.last.is_a? Hash
9
- opts ||= {}
10
-
11
- if args.size == 1 and args.first.is_a? Transport::Buffer
12
- buf = args.shift
13
- else
14
- buf = nil
15
- end
16
-
17
- self.class.arguments.each do |type, name|
18
- val = buf ? buf.read(type) :
19
- args.shift || opts[name] || opts[name.to_s]
20
- instance_variable_set("@#{name}", val)
21
- end
22
- end
23
-
24
- def arguments
25
- self.class.arguments.inject({}) do |hash, (type, name)|
26
- hash.update name => instance_variable_get("@#{name}")
27
- end
28
- end
29
-
30
- def to_binary
31
- buf = Transport::Buffer.new
32
- buf.write :short, self.class.parent.id
33
- buf.write :short, self.class.id
34
-
35
- bits = []
36
-
37
- self.class.arguments.each do |type, name|
38
- val = instance_variable_get("@#{name}")
39
- if type == :bit
40
- bits << (val || false)
41
- else
42
- unless bits.empty?
43
- buf.write :bit, bits
44
- bits = []
45
- end
46
- buf.write type, val
47
- end
48
- end
49
-
50
- buf.write :bit, bits unless bits.empty?
51
- buf.rewind
52
-
53
- buf
54
- end
55
-
56
- def to_s
57
- to_binary.to_s
58
- end
59
-
60
- def to_frame channel = 0
61
- Transport::Method.new(self, channel)
62
- end
63
- end
64
-
65
- class Header
66
- def initialize *args
67
- opts = args.pop if args.last.is_a? Hash
68
- opts ||= {}
69
-
70
- first = args.shift
71
-
72
- if first.is_a? ::Class and first.ancestors.include? Protocol::Class
73
- @klass = first
74
- @size = args.shift || 0
75
- @weight = args.shift || 0
76
- @properties = opts
77
-
78
- elsif first.is_a? Transport::Buffer or first.is_a? String
79
- buf = first
80
- buf = Transport::Buffer.new(buf) unless buf.is_a? Transport::Buffer
81
-
82
- @klass = Protocol.classes[buf.read(:short)]
83
- @weight = buf.read(:short)
84
- @size = buf.read(:longlong)
85
-
86
- props = buf.read(:properties, *klass.properties.map{|type,_| type })
87
- @properties = Hash[*klass.properties.map{|_,name| name }.zip(props).reject{|k,v| v.nil? }.flatten]
88
-
89
- else
90
- raise ArgumentError, 'Invalid argument'
91
- end
92
-
93
- end
94
- attr_accessor :klass, :size, :weight, :properties
95
-
96
- def to_binary
97
- buf = Transport::Buffer.new
98
- buf.write :short, klass.id
99
- buf.write :short, weight # XXX rabbitmq only supports weight == 0
100
- buf.write :longlong, size
101
- buf.write :properties, (klass.properties.map do |type, name|
102
- [ type, properties[name] || properties[name.to_s] ]
103
- end)
104
- buf.rewind
105
- buf
106
- end
107
-
108
- def to_s
109
- to_binary.to_s
110
- end
111
-
112
- def to_frame channel = 0
113
- Transport::Header.new(self, channel)
114
- end
115
-
116
- def == header
117
- [ :klass, :size, :weight, :properties ].inject(true) do |eql, field|
118
- eql and __send__(field) == header.__send__(field)
119
- end
120
- end
121
-
122
- def method_missing meth, *args, &blk
123
- @properties.has_key?(meth) || @klass.properties.find{|_,name| name == meth } ? @properties[meth] :
124
- super
125
- end
126
- end
127
-
128
- def self.parse buf
129
- buf = Transport::Buffer.new(buf) unless buf.is_a? Transport::Buffer
130
- class_id, method_id = buf.read(:short, :short)
131
- classes[class_id].methods[method_id].new(buf)
132
- end
133
-
134
- end
135
- end
@@ -1,525 +0,0 @@
1
-
2
- # encoding: utf-8
3
-
4
-
5
- #:stopdoc:
6
- # this file was autogenerated on 2012-02-28 11:22:27 -0500
7
- # using amqp-0.9.1.json (mtime: 2012-02-28 10:50:44 -0500)
8
- #
9
- # DO NOT EDIT! (edit ext/qparser.rb and config.yml instead, and run 'ruby qparser.rb')
10
-
11
- module Qrack
12
- module Protocol
13
- HEADER = "AMQP".freeze
14
- VERSION_MAJOR = 0
15
- VERSION_MINOR = 9
16
- REVISION = 1
17
- PORT = 5672
18
- SSL_PORT = 5671
19
-
20
- RESPONSES = {
21
- 200 => :REPLY_SUCCESS,
22
- 311 => :CONTENT_TOO_LARGE,
23
- 312 => :NO_ROUTE,
24
- 313 => :NO_CONSUMERS,
25
- 320 => :CONNECTION_FORCED,
26
- 402 => :INVALID_PATH,
27
- 403 => :ACCESS_REFUSED,
28
- 404 => :NOT_FOUND,
29
- 405 => :RESOURCE_LOCKED,
30
- 406 => :PRECONDITION_FAILED,
31
- 502 => :SYNTAX_ERROR,
32
- 503 => :COMMAND_INVALID,
33
- 504 => :CHANNEL_ERROR,
34
- 505 => :UNEXPECTED_FRAME,
35
- 506 => :RESOURCE_ERROR,
36
- 530 => :NOT_ALLOWED,
37
- 540 => :NOT_IMPLEMENTED,
38
- 541 => :INTERNAL_ERROR,
39
- }
40
-
41
- FIELDS = [
42
- :bit,
43
- :long,
44
- :longlong,
45
- :longstr,
46
- :octet,
47
- :short,
48
- :shortstr,
49
- :table,
50
- :timestamp,
51
- ]
52
-
53
- class Class
54
- class << self
55
- FIELDS.each do |f|
56
- class_eval %[
57
- def #{f} name
58
- properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
59
- attr_accessor name
60
- end
61
- ]
62
- end
63
-
64
- def properties() @properties ||= [] end
65
-
66
- def id() self::ID end
67
- def name() self::NAME.to_s end
68
- end
69
-
70
- class Method
71
- class << self
72
- FIELDS.each do |f|
73
- class_eval %[
74
- def #{f} name
75
- arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
76
- attr_accessor name
77
- end
78
- ]
79
- end
80
-
81
- def arguments() @arguments ||= [] end
82
-
83
- def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
84
- def id() self::ID end
85
- def name() self::NAME.to_s end
86
- end
87
-
88
- def == b
89
- self.class.arguments.inject(true) do |eql, (type, name)|
90
- eql and __send__("#{name}") == b.__send__("#{name}")
91
- end
92
- end
93
- end
94
-
95
- def self.methods() @methods ||= {} end
96
-
97
- def self.Method(id, name)
98
- @_base_methods ||= {}
99
- @_base_methods[id] ||= ::Class.new(Method) do
100
- class_eval %[
101
- def self.inherited klass
102
- klass.const_set(:ID, #{id})
103
- klass.const_set(:NAME, :#{name.to_s})
104
- klass.parent.methods[#{id}] = klass
105
- klass.parent.methods[klass::NAME] = klass
106
- end
107
- ]
108
- end
109
- end
110
- end
111
-
112
- def self.classes() @classes ||= {} end
113
-
114
- def self.Class(id, name)
115
- @_base_classes ||= {}
116
- @_base_classes[id] ||= ::Class.new(Class) do
117
- class_eval %[
118
- def self.inherited klass
119
- klass.const_set(:ID, #{id})
120
- klass.const_set(:NAME, :#{name.to_s})
121
- Protocol.classes[#{id}] = klass
122
- Protocol.classes[klass::NAME] = klass
123
- end
124
- ]
125
- end
126
- end
127
- end
128
- end
129
-
130
- module Qrack
131
- module Protocol
132
- class Connection < Class( 10, :connection ); end
133
- class Channel < Class( 20, :channel ); end
134
- class Exchange < Class( 40, :exchange ); end
135
- class Queue < Class( 50, :queue ); end
136
- class Basic < Class( 60, :basic ); end
137
- class Tx < Class( 90, :tx ); end
138
-
139
- class Connection
140
-
141
- class Start < Method( 10, :start ); end
142
- class StartOk < Method( 11, :start_ok ); end
143
- class Secure < Method( 20, :secure ); end
144
- class SecureOk < Method( 21, :secure_ok ); end
145
- class Tune < Method( 30, :tune ); end
146
- class TuneOk < Method( 31, :tune_ok ); end
147
- class Open < Method( 40, :open ); end
148
- class OpenOk < Method( 41, :open_ok ); end
149
- class Close < Method( 50, :close ); end
150
- class CloseOk < Method( 51, :close_ok ); end
151
-
152
-
153
- class Start
154
- octet :version_major
155
- octet :version_minor
156
- table :server_properties
157
- longstr :mechanisms
158
- longstr :locales
159
- end
160
-
161
- class StartOk
162
- table :client_properties
163
- shortstr :mechanism
164
- longstr :response
165
- shortstr :locale
166
- end
167
-
168
- class Secure
169
- longstr :challenge
170
- end
171
-
172
- class SecureOk
173
- longstr :response
174
- end
175
-
176
- class Tune
177
- short :channel_max
178
- long :frame_max
179
- short :heartbeat
180
- end
181
-
182
- class TuneOk
183
- short :channel_max
184
- long :frame_max
185
- short :heartbeat
186
- end
187
-
188
- class Open
189
- shortstr :virtual_host
190
- shortstr :deprecated_capabilities
191
- bit :deprecated_insist
192
- end
193
-
194
- class OpenOk
195
- shortstr :deprecated_known_hosts
196
- end
197
-
198
- class Close
199
- short :reply_code
200
- shortstr :reply_text
201
- short :class_id
202
- short :method_id
203
- end
204
-
205
- class CloseOk
206
- end
207
-
208
- end
209
-
210
- class Channel
211
-
212
- class Open < Method( 10, :open ); end
213
- class OpenOk < Method( 11, :open_ok ); end
214
- class Flow < Method( 20, :flow ); end
215
- class FlowOk < Method( 21, :flow_ok ); end
216
- class Close < Method( 40, :close ); end
217
- class CloseOk < Method( 41, :close_ok ); end
218
-
219
-
220
- class Open
221
- shortstr :deprecated_out_of_band
222
- end
223
-
224
- class OpenOk
225
- longstr :deprecated_channel_id
226
- end
227
-
228
- class Flow
229
- bit :active
230
- end
231
-
232
- class FlowOk
233
- bit :active
234
- end
235
-
236
- class Close
237
- short :reply_code
238
- shortstr :reply_text
239
- short :class_id
240
- short :method_id
241
- end
242
-
243
- class CloseOk
244
- end
245
-
246
- end
247
-
248
- class Exchange
249
-
250
- class Declare < Method( 10, :declare ); end
251
- class DeclareOk < Method( 11, :declare_ok ); end
252
- class Delete < Method( 20, :delete ); end
253
- class DeleteOk < Method( 21, :delete_ok ); end
254
-
255
-
256
- class Declare
257
- short :deprecated_ticket
258
- shortstr :exchange
259
- shortstr :type
260
- bit :passive
261
- bit :durable
262
- bit :deprecated_auto_delete
263
- bit :deprecated_internal
264
- bit :nowait
265
- table :arguments
266
- end
267
-
268
- class DeclareOk
269
- end
270
-
271
- class Delete
272
- short :deprecated_ticket
273
- shortstr :exchange
274
- bit :if_unused
275
- bit :nowait
276
- end
277
-
278
- class DeleteOk
279
- end
280
-
281
- end
282
-
283
- class Queue
284
-
285
- class Declare < Method( 10, :declare ); end
286
- class DeclareOk < Method( 11, :declare_ok ); end
287
- class Bind < Method( 20, :bind ); end
288
- class BindOk < Method( 21, :bind_ok ); end
289
- class Purge < Method( 30, :purge ); end
290
- class PurgeOk < Method( 31, :purge_ok ); end
291
- class Delete < Method( 40, :delete ); end
292
- class DeleteOk < Method( 41, :delete_ok ); end
293
- class Unbind < Method( 50, :unbind ); end
294
- class UnbindOk < Method( 51, :unbind_ok ); end
295
-
296
-
297
- class Declare
298
- short :deprecated_ticket
299
- shortstr :queue
300
- bit :passive
301
- bit :durable
302
- bit :exclusive
303
- bit :auto_delete
304
- bit :nowait
305
- table :arguments
306
- end
307
-
308
- class DeclareOk
309
- shortstr :queue
310
- long :message_count
311
- long :consumer_count
312
- end
313
-
314
- class Bind
315
- short :deprecated_ticket
316
- shortstr :queue
317
- shortstr :exchange
318
- shortstr :routing_key
319
- bit :nowait
320
- table :arguments
321
- end
322
-
323
- class BindOk
324
- end
325
-
326
- class Purge
327
- short :deprecated_ticket
328
- shortstr :queue
329
- bit :nowait
330
- end
331
-
332
- class PurgeOk
333
- long :message_count
334
- end
335
-
336
- class Delete
337
- short :deprecated_ticket
338
- shortstr :queue
339
- bit :if_unused
340
- bit :if_empty
341
- bit :nowait
342
- end
343
-
344
- class DeleteOk
345
- long :message_count
346
- end
347
-
348
- class Unbind
349
- short :deprecated_ticket
350
- shortstr :queue
351
- shortstr :exchange
352
- shortstr :routing_key
353
- table :arguments
354
- end
355
-
356
- class UnbindOk
357
- end
358
-
359
- end
360
-
361
- class Basic
362
- shortstr :content_type
363
- shortstr :content_encoding
364
- table :headers
365
- octet :delivery_mode
366
- octet :priority
367
- shortstr :correlation_id
368
- shortstr :reply_to
369
- shortstr :expiration
370
- shortstr :message_id
371
- timestamp :timestamp
372
- shortstr :type
373
- shortstr :user_id
374
- shortstr :app_id
375
- shortstr :deprecated_cluster_id
376
-
377
- class Qos < Method( 10, :qos ); end
378
- class QosOk < Method( 11, :qos_ok ); end
379
- class Consume < Method( 20, :consume ); end
380
- class ConsumeOk < Method( 21, :consume_ok ); end
381
- class Cancel < Method( 30, :cancel ); end
382
- class CancelOk < Method( 31, :cancel_ok ); end
383
- class Publish < Method( 40, :publish ); end
384
- class Return < Method( 50, :return ); end
385
- class Deliver < Method( 60, :deliver ); end
386
- class Get < Method( 70, :get ); end
387
- class GetOk < Method( 71, :get_ok ); end
388
- class GetEmpty < Method( 72, :get_empty ); end
389
- class Ack < Method( 80, :ack ); end
390
- class Reject < Method( 90, :reject ); end
391
- class RecoverAsync < Method( 100, :recover_async ); end
392
- class Recover < Method( 110, :recover ); end
393
- class RecoverOk < Method( 111, :recover_ok ); end
394
-
395
-
396
- class Qos
397
- long :prefetch_size
398
- short :prefetch_count
399
- bit :global
400
- end
401
-
402
- class QosOk
403
- end
404
-
405
- class Consume
406
- short :deprecated_ticket
407
- shortstr :queue
408
- shortstr :consumer_tag
409
- bit :no_local
410
- bit :no_ack
411
- bit :exclusive
412
- bit :nowait
413
- table :filter
414
- end
415
-
416
- class ConsumeOk
417
- shortstr :consumer_tag
418
- end
419
-
420
- class Cancel
421
- shortstr :consumer_tag
422
- bit :nowait
423
- end
424
-
425
- class CancelOk
426
- shortstr :consumer_tag
427
- end
428
-
429
- class Publish
430
- short :deprecated_ticket
431
- shortstr :exchange
432
- shortstr :routing_key
433
- bit :mandatory
434
- bit :immediate
435
- end
436
-
437
- class Return
438
- short :reply_code
439
- shortstr :reply_text
440
- shortstr :exchange
441
- shortstr :routing_key
442
- end
443
-
444
- class Deliver
445
- shortstr :consumer_tag
446
- longlong :delivery_tag
447
- bit :redelivered
448
- shortstr :exchange
449
- shortstr :routing_key
450
- end
451
-
452
- class Get
453
- short :deprecated_ticket
454
- shortstr :queue
455
- bit :no_ack
456
- end
457
-
458
- class GetOk
459
- longlong :delivery_tag
460
- bit :redelivered
461
- shortstr :exchange
462
- shortstr :routing_key
463
- long :message_count
464
- end
465
-
466
- class GetEmpty
467
- shortstr :deprecated_cluster_id
468
- end
469
-
470
- class Ack
471
- longlong :delivery_tag
472
- bit :multiple
473
- end
474
-
475
- class Reject
476
- longlong :delivery_tag
477
- bit :requeue
478
- end
479
-
480
- class RecoverAsync
481
- bit :requeue
482
- end
483
-
484
- class Recover
485
- bit :requeue
486
- end
487
-
488
- class RecoverOk
489
- end
490
-
491
- end
492
-
493
- class Tx
494
-
495
- class Select < Method( 10, :select ); end
496
- class SelectOk < Method( 11, :select_ok ); end
497
- class Commit < Method( 20, :commit ); end
498
- class CommitOk < Method( 21, :commit_ok ); end
499
- class Rollback < Method( 30, :rollback ); end
500
- class RollbackOk < Method( 31, :rollback_ok ); end
501
-
502
-
503
- class Select
504
- end
505
-
506
- class SelectOk
507
- end
508
-
509
- class Commit
510
- end
511
-
512
- class CommitOk
513
- end
514
-
515
- class Rollback
516
- end
517
-
518
- class RollbackOk
519
- end
520
-
521
- end
522
-
523
- end
524
-
525
- end