amqp 0.7.0.pre → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +2 -0
  3. data/CHANGELOG +8 -2
  4. data/CONTRIBUTORS +22 -0
  5. data/Gemfile +3 -3
  6. data/README.md +20 -11
  7. data/Rakefile +30 -6
  8. data/amqp.gemspec +1 -1
  9. data/bin/cleanify.rb +50 -0
  10. data/examples/amqp/simple.rb +6 -4
  11. data/examples/mq/ack.rb +8 -6
  12. data/examples/mq/automatic_binding_for_default_direct_exchange.rb +65 -0
  13. data/examples/mq/callbacks.rb +9 -1
  14. data/examples/mq/clock.rb +17 -17
  15. data/examples/mq/hashtable.rb +19 -10
  16. data/examples/mq/internal.rb +13 -11
  17. data/examples/mq/logger.rb +38 -36
  18. data/examples/mq/multiclock.rb +16 -7
  19. data/examples/mq/pingpong.rb +16 -7
  20. data/examples/mq/pop.rb +8 -6
  21. data/examples/mq/primes-simple.rb +2 -0
  22. data/examples/mq/primes.rb +7 -5
  23. data/examples/mq/stocks.rb +14 -5
  24. data/lib/amqp.rb +12 -8
  25. data/lib/amqp/buffer.rb +35 -158
  26. data/lib/amqp/client.rb +34 -22
  27. data/lib/amqp/frame.rb +8 -64
  28. data/lib/amqp/protocol.rb +21 -70
  29. data/lib/amqp/server.rb +11 -9
  30. data/lib/amqp/spec.rb +8 -6
  31. data/lib/amqp/version.rb +2 -0
  32. data/lib/ext/blankslate.rb +3 -1
  33. data/lib/ext/em.rb +2 -0
  34. data/lib/ext/emfork.rb +13 -11
  35. data/lib/mq.rb +253 -156
  36. data/lib/mq/collection.rb +6 -88
  37. data/lib/mq/exchange.rb +70 -13
  38. data/lib/mq/header.rb +12 -6
  39. data/lib/mq/logger.rb +9 -7
  40. data/lib/mq/queue.rb +42 -30
  41. data/lib/mq/rpc.rb +6 -4
  42. data/protocol/codegen.rb +20 -18
  43. data/research/api.rb +10 -46
  44. data/research/primes-forked.rb +9 -7
  45. data/research/primes-processes.rb +74 -72
  46. data/research/primes-threaded.rb +9 -7
  47. data/spec/integration/automatic_binding_for_default_direct_exchange_spec.rb +61 -0
  48. data/spec/mq_helper.rb +70 -0
  49. data/spec/spec_helper.rb +84 -29
  50. data/spec/unit/amqp/buffer_spec.rb +178 -0
  51. data/spec/unit/amqp/client_spec.rb +472 -0
  52. data/spec/unit/amqp/frame_spec.rb +60 -0
  53. data/spec/unit/amqp/misc_spec.rb +123 -0
  54. data/spec/unit/amqp/protocol_spec.rb +53 -0
  55. data/spec/unit/mq/channel_close_spec.rb +15 -0
  56. data/spec/unit/mq/collection_spec.rb +129 -0
  57. data/spec/unit/mq/exchange_declaration_spec.rb +524 -0
  58. data/spec/unit/mq/misc_spec.rb +228 -0
  59. data/spec/unit/mq/mq_basic_spec.rb +39 -0
  60. data/spec/unit/mq/queue_declaration_spec.rb +97 -0
  61. data/spec/unit/mq/queue_spec.rb +71 -0
  62. metadata +33 -21
  63. data/Gemfile.lock +0 -16
  64. data/old/README +0 -30
  65. data/old/Rakefile +0 -12
  66. data/old/amqp-0.8.json +0 -606
  67. data/old/amqp_spec.rb +0 -796
  68. data/old/amqpc.rb +0 -695
  69. data/old/codegen.rb +0 -148
  70. data/spec/channel_close_spec.rb +0 -13
  71. data/spec/sync_async_spec.rb +0 -52
@@ -1,796 +0,0 @@
1
-
2
- module AMQP
3
- HEADER = "AMQP".freeze
4
- VERSION_MAJOR = 8
5
- VERSION_MINOR = 0
6
- PORT = 5672
7
-
8
- class Frame
9
- TYPES = [
10
- nil,
11
- :METHOD,
12
- :HEADER,
13
- :BODY,
14
- :OOB_METHOD,
15
- :OOB_HEADER,
16
- :OOB_BODY,
17
- :TRACE,
18
- :HEARTBEAT,
19
- ]
20
- FOOTER = 206
21
- end
22
-
23
- RESPONSES = {
24
- 200 => :REPLY_SUCCESS,
25
- 310 => :NOT_DELIVERED,
26
- 311 => :CONTENT_TOO_LARGE,
27
- 312 => :NO_ROUTE,
28
- 313 => :NO_CONSUMERS,
29
- 403 => :ACCESS_REFUSED,
30
- 404 => :NOT_FOUND,
31
- 405 => :RESOURCE_LOCKED,
32
- 406 => :PRECONDITION_FAILED,
33
- 320 => :CONNECTION_FORCED,
34
- 402 => :INVALID_PATH,
35
- }
36
-
37
- FIELDS = [
38
- :bit,
39
- :long,
40
- :longlong,
41
- :longstr,
42
- :octet,
43
- :short,
44
- :shortstr,
45
- :table,
46
- :timestamp,
47
- ]
48
-
49
- module Protocol
50
- class Class
51
- class << self
52
- FIELDS.each do |f|
53
- class_eval %[
54
- def #{f} name
55
- properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
56
- attr_accessor name
57
- end
58
- ]
59
- end
60
-
61
- def properties() @properties ||= [] end
62
-
63
- def id() self::ID end
64
- def name() self::NAME end
65
- end
66
-
67
- class Method
68
- class << self
69
- FIELDS.each do |f|
70
- class_eval %[
71
- def #{f} name
72
- arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
73
- attr_accessor name
74
- end
75
- ]
76
- end
77
-
78
- def arguments() @arguments ||= [] end
79
-
80
- def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
81
- def id() self::ID end
82
- def name() self::NAME end
83
- end
84
-
85
- def == b
86
- self.class.arguments.inject(true) do |eql, (type, name)|
87
- eql and __send__("#{name}") == b.__send__("#{name}")
88
- end
89
- end
90
- end
91
-
92
- def self.methods() @methods ||= {} end
93
-
94
- def self.Method(id, name)
95
- @_base_methods ||= {}
96
- @_base_methods[id] ||= ::Class.new(Method) do
97
- class_eval %[
98
- def self.inherited klass
99
- klass.const_set(:ID, #{id})
100
- klass.const_set(:NAME, :#{name.to_s})
101
- klass.parent.methods[#{id}] = klass
102
- klass.parent.methods[klass::NAME] = klass
103
- end
104
- ]
105
- end
106
- end
107
- end
108
-
109
- def self.classes() @classes ||= {} end
110
-
111
- def self.Class(id, name)
112
- @_base_classes ||= {}
113
- @_base_classes[id] ||= ::Class.new(Class) do
114
- class_eval %[
115
- def self.inherited klass
116
- klass.const_set(:ID, #{id})
117
- klass.const_set(:NAME, :#{name.to_s})
118
- Protocol.classes[#{id}] = klass
119
- Protocol.classes[klass::NAME] = klass
120
- end
121
- ]
122
- end
123
- end
124
-
125
- class Connection < Class(10, :connection); end
126
- class Channel < Class(20, :channel); end
127
- class Access < Class(30, :access); end
128
- class Exchange < Class(40, :exchange); end
129
- class Queue < Class(50, :queue); end
130
- class Basic < Class(60, :basic); end
131
- class File < Class(70, :file); end
132
- class Stream < Class(80, :stream); end
133
- class Tx < Class(90, :tx); end
134
- class Dtx < Class(100, :dtx); end
135
- class Tunnel < Class(110, :tunnel); end
136
- class Test < Class(120, :test); end
137
-
138
- class Connection
139
-
140
- class Start < Method(10, :start); end
141
- class StartOk < Method(11, :start_ok); end
142
- class Secure < Method(20, :secure); end
143
- class SecureOk < Method(21, :secure_ok); end
144
- class Tune < Method(30, :tune); end
145
- class TuneOk < Method(31, :tune_ok); end
146
- class Open < Method(40, :open); end
147
- class OpenOk < Method(41, :open_ok); end
148
- class Redirect < Method(50, :redirect); end
149
- class Close < Method(60, :close); end
150
- class CloseOk < Method(61, :close_ok); end
151
-
152
- class Start
153
- octet :version_major
154
- octet :version_minor
155
- table :server_properties
156
- longstr :mechanisms
157
- longstr :locales
158
- end
159
-
160
- class StartOk
161
- table :client_properties
162
- shortstr :mechanism
163
- longstr :response
164
- shortstr :locale
165
- end
166
-
167
- class Secure
168
- longstr :challenge
169
- end
170
-
171
- class SecureOk
172
- longstr :response
173
- end
174
-
175
- class Tune
176
- short :channel_max
177
- long :frame_max
178
- short :heartbeat
179
- end
180
-
181
- class TuneOk
182
- short :channel_max
183
- long :frame_max
184
- short :heartbeat
185
- end
186
-
187
- class Open
188
- shortstr :virtual_host
189
- shortstr :capabilities
190
- bit :insist
191
- end
192
-
193
- class OpenOk
194
- shortstr :known_hosts
195
- end
196
-
197
- class Redirect
198
- shortstr :host
199
- shortstr :known_hosts
200
- end
201
-
202
- class Close
203
- short :reply_code
204
- shortstr :reply_text
205
- short :class_id
206
- short :method_id
207
- end
208
-
209
- class CloseOk
210
- end
211
-
212
- end
213
-
214
- class Channel
215
-
216
- class Open < Method(10, :open); end
217
- class OpenOk < Method(11, :open_ok); end
218
- class Flow < Method(20, :flow); end
219
- class FlowOk < Method(21, :flow_ok); end
220
- class Alert < Method(30, :alert); end
221
- class Close < Method(40, :close); end
222
- class CloseOk < Method(41, :close_ok); end
223
-
224
- class Open
225
- shortstr :out_of_band
226
- end
227
-
228
- class OpenOk
229
- end
230
-
231
- class Flow
232
- bit :active
233
- end
234
-
235
- class FlowOk
236
- bit :active
237
- end
238
-
239
- class Alert
240
- short :reply_code
241
- shortstr :reply_text
242
- table :details
243
- end
244
-
245
- class Close
246
- short :reply_code
247
- shortstr :reply_text
248
- short :class_id
249
- short :method_id
250
- end
251
-
252
- class CloseOk
253
- end
254
-
255
- end
256
-
257
- class Access
258
-
259
- class Request < Method(10, :request); end
260
- class RequestOk < Method(11, :request_ok); end
261
-
262
- class Request
263
- shortstr :realm
264
- bit :exclusive
265
- bit :passive
266
- bit :active
267
- bit :write
268
- bit :read
269
- end
270
-
271
- class RequestOk
272
- short :ticket
273
- end
274
-
275
- end
276
-
277
- class Exchange
278
-
279
- class Declare < Method(10, :declare); end
280
- class DeclareOk < Method(11, :declare_ok); end
281
- class Delete < Method(20, :delete); end
282
- class DeleteOk < Method(21, :delete_ok); end
283
-
284
- class Declare
285
- short :ticket
286
- shortstr :exchange
287
- shortstr :type
288
- bit :passive
289
- bit :durable
290
- bit :auto_delete
291
- bit :internal
292
- bit :nowait
293
- table :arguments
294
- end
295
-
296
- class DeclareOk
297
- end
298
-
299
- class Delete
300
- short :ticket
301
- shortstr :exchange
302
- bit :if_unused
303
- bit :nowait
304
- end
305
-
306
- class DeleteOk
307
- end
308
-
309
- end
310
-
311
- class Queue
312
-
313
- class Declare < Method(10, :declare); end
314
- class DeclareOk < Method(11, :declare_ok); end
315
- class Bind < Method(20, :bind); end
316
- class BindOk < Method(21, :bind_ok); end
317
- class Purge < Method(30, :purge); end
318
- class PurgeOk < Method(31, :purge_ok); end
319
- class Delete < Method(40, :delete); end
320
- class DeleteOk < Method(41, :delete_ok); end
321
-
322
- class Declare
323
- short :ticket
324
- shortstr :queue
325
- bit :passive
326
- bit :durable
327
- bit :exclusive
328
- bit :auto_delete
329
- bit :nowait
330
- table :arguments
331
- end
332
-
333
- class DeclareOk
334
- shortstr :queue
335
- long :message_count
336
- long :consumer_count
337
- end
338
-
339
- class Bind
340
- short :ticket
341
- shortstr :queue
342
- shortstr :exchange
343
- shortstr :routing_key
344
- bit :nowait
345
- table :arguments
346
- end
347
-
348
- class BindOk
349
- end
350
-
351
- class Purge
352
- short :ticket
353
- shortstr :queue
354
- bit :nowait
355
- end
356
-
357
- class PurgeOk
358
- long :message_count
359
- end
360
-
361
- class Delete
362
- short :ticket
363
- shortstr :queue
364
- bit :if_unused
365
- bit :if_empty
366
- bit :nowait
367
- end
368
-
369
- class DeleteOk
370
- long :message_count
371
- end
372
-
373
- end
374
-
375
- class Basic
376
- shortstr :content_type
377
- shortstr :content_encoding
378
- table :headers
379
- octet :delivery_mode
380
- octet :priority
381
- shortstr :correlation_id
382
- shortstr :reply_to
383
- shortstr :expiration
384
- shortstr :message_id
385
- timestamp :timestamp
386
- shortstr :type
387
- shortstr :user_id
388
- shortstr :app_id
389
- shortstr :cluster_id
390
-
391
- class Qos < Method(10, :qos); end
392
- class QosOk < Method(11, :qos_ok); end
393
- class Consume < Method(20, :consume); end
394
- class ConsumeOk < Method(21, :consume_ok); end
395
- class Cancel < Method(30, :cancel); end
396
- class CancelOk < Method(31, :cancel_ok); end
397
- class Publish < Method(40, :publish); end
398
- class Return < Method(50, :return); end
399
- class Deliver < Method(60, :deliver); end
400
- class Get < Method(70, :get); end
401
- class GetOk < Method(71, :get_ok); end
402
- class GetEmpty < Method(72, :get_empty); end
403
- class Ack < Method(80, :ack); end
404
- class Reject < Method(90, :reject); end
405
- class Recover < Method(100, :recover); end
406
-
407
- class Qos
408
- long :prefetch_size
409
- short :prefetch_count
410
- bit :global
411
- end
412
-
413
- class QosOk
414
- end
415
-
416
- class Consume
417
- short :ticket
418
- shortstr :queue
419
- shortstr :consumer_tag
420
- bit :no_local
421
- bit :no_ack
422
- bit :exclusive
423
- bit :nowait
424
- end
425
-
426
- class ConsumeOk
427
- shortstr :consumer_tag
428
- end
429
-
430
- class Cancel
431
- shortstr :consumer_tag
432
- bit :nowait
433
- end
434
-
435
- class CancelOk
436
- shortstr :consumer_tag
437
- end
438
-
439
- class Publish
440
- short :ticket
441
- shortstr :exchange
442
- shortstr :routing_key
443
- bit :mandatory
444
- bit :immediate
445
- end
446
-
447
- class Return
448
- short :reply_code
449
- shortstr :reply_text
450
- shortstr :exchange
451
- shortstr :routing_key
452
- end
453
-
454
- class Deliver
455
- shortstr :consumer_tag
456
- longlong :delivery_tag
457
- bit :redelivered
458
- shortstr :exchange
459
- shortstr :routing_key
460
- end
461
-
462
- class Get
463
- short :ticket
464
- shortstr :queue
465
- bit :no_ack
466
- end
467
-
468
- class GetOk
469
- longlong :delivery_tag
470
- bit :redelivered
471
- shortstr :exchange
472
- shortstr :routing_key
473
- long :message_count
474
- end
475
-
476
- class GetEmpty
477
- shortstr :cluster_id
478
- end
479
-
480
- class Ack
481
- longlong :delivery_tag
482
- bit :multiple
483
- end
484
-
485
- class Reject
486
- longlong :delivery_tag
487
- bit :requeue
488
- end
489
-
490
- class Recover
491
- bit :requeue
492
- end
493
-
494
- end
495
-
496
- class File
497
- shortstr :content_type
498
- shortstr :content_encoding
499
- table :headers
500
- octet :priority
501
- shortstr :reply_to
502
- shortstr :message_id
503
- shortstr :filename
504
- timestamp :timestamp
505
- shortstr :cluster_id
506
-
507
- class Qos < Method(10, :qos); end
508
- class QosOk < Method(11, :qos_ok); end
509
- class Consume < Method(20, :consume); end
510
- class ConsumeOk < Method(21, :consume_ok); end
511
- class Cancel < Method(30, :cancel); end
512
- class CancelOk < Method(31, :cancel_ok); end
513
- class Open < Method(40, :open); end
514
- class OpenOk < Method(41, :open_ok); end
515
- class Stage < Method(50, :stage); end
516
- class Publish < Method(60, :publish); end
517
- class Return < Method(70, :return); end
518
- class Deliver < Method(80, :deliver); end
519
- class Ack < Method(90, :ack); end
520
- class Reject < Method(100, :reject); end
521
-
522
- class Qos
523
- long :prefetch_size
524
- short :prefetch_count
525
- bit :global
526
- end
527
-
528
- class QosOk
529
- end
530
-
531
- class Consume
532
- short :ticket
533
- shortstr :queue
534
- shortstr :consumer_tag
535
- bit :no_local
536
- bit :no_ack
537
- bit :exclusive
538
- bit :nowait
539
- end
540
-
541
- class ConsumeOk
542
- shortstr :consumer_tag
543
- end
544
-
545
- class Cancel
546
- shortstr :consumer_tag
547
- bit :nowait
548
- end
549
-
550
- class CancelOk
551
- shortstr :consumer_tag
552
- end
553
-
554
- class Open
555
- shortstr :identifier
556
- longlong :content_size
557
- end
558
-
559
- class OpenOk
560
- longlong :staged_size
561
- end
562
-
563
- class Stage
564
- end
565
-
566
- class Publish
567
- short :ticket
568
- shortstr :exchange
569
- shortstr :routing_key
570
- bit :mandatory
571
- bit :immediate
572
- shortstr :identifier
573
- end
574
-
575
- class Return
576
- short :reply_code
577
- shortstr :reply_text
578
- shortstr :exchange
579
- shortstr :routing_key
580
- end
581
-
582
- class Deliver
583
- shortstr :consumer_tag
584
- longlong :delivery_tag
585
- bit :redelivered
586
- shortstr :exchange
587
- shortstr :routing_key
588
- shortstr :identifier
589
- end
590
-
591
- class Ack
592
- longlong :delivery_tag
593
- bit :multiple
594
- end
595
-
596
- class Reject
597
- longlong :delivery_tag
598
- bit :requeue
599
- end
600
-
601
- end
602
-
603
- class Stream
604
- shortstr :content_type
605
- shortstr :content_encoding
606
- table :headers
607
- octet :priority
608
- timestamp :timestamp
609
-
610
- class Qos < Method(10, :qos); end
611
- class QosOk < Method(11, :qos_ok); end
612
- class Consume < Method(20, :consume); end
613
- class ConsumeOk < Method(21, :consume_ok); end
614
- class Cancel < Method(30, :cancel); end
615
- class CancelOk < Method(31, :cancel_ok); end
616
- class Publish < Method(40, :publish); end
617
- class Return < Method(50, :return); end
618
- class Deliver < Method(60, :deliver); end
619
-
620
- class Qos
621
- long :prefetch_size
622
- short :prefetch_count
623
- long :consume_rate
624
- bit :global
625
- end
626
-
627
- class QosOk
628
- end
629
-
630
- class Consume
631
- short :ticket
632
- shortstr :queue
633
- shortstr :consumer_tag
634
- bit :no_local
635
- bit :exclusive
636
- bit :nowait
637
- end
638
-
639
- class ConsumeOk
640
- shortstr :consumer_tag
641
- end
642
-
643
- class Cancel
644
- shortstr :consumer_tag
645
- bit :nowait
646
- end
647
-
648
- class CancelOk
649
- shortstr :consumer_tag
650
- end
651
-
652
- class Publish
653
- short :ticket
654
- shortstr :exchange
655
- shortstr :routing_key
656
- bit :mandatory
657
- bit :immediate
658
- end
659
-
660
- class Return
661
- short :reply_code
662
- shortstr :reply_text
663
- shortstr :exchange
664
- shortstr :routing_key
665
- end
666
-
667
- class Deliver
668
- shortstr :consumer_tag
669
- longlong :delivery_tag
670
- shortstr :exchange
671
- shortstr :queue
672
- end
673
-
674
- end
675
-
676
- class Tx
677
-
678
- class Select < Method(10, :select); end
679
- class SelectOk < Method(11, :select_ok); end
680
- class Commit < Method(20, :commit); end
681
- class CommitOk < Method(21, :commit_ok); end
682
- class Rollback < Method(30, :rollback); end
683
- class RollbackOk < Method(31, :rollback_ok); end
684
-
685
- class Select
686
- end
687
-
688
- class SelectOk
689
- end
690
-
691
- class Commit
692
- end
693
-
694
- class CommitOk
695
- end
696
-
697
- class Rollback
698
- end
699
-
700
- class RollbackOk
701
- end
702
-
703
- end
704
-
705
- class Dtx
706
-
707
- class Select < Method(10, :select); end
708
- class SelectOk < Method(11, :select_ok); end
709
- class Start < Method(20, :start); end
710
- class StartOk < Method(21, :start_ok); end
711
-
712
- class Select
713
- end
714
-
715
- class SelectOk
716
- end
717
-
718
- class Start
719
- shortstr :dtx_identifier
720
- end
721
-
722
- class StartOk
723
- end
724
-
725
- end
726
-
727
- class Tunnel
728
- table :headers
729
- shortstr :proxy_name
730
- shortstr :data_name
731
- octet :durable
732
- octet :broadcast
733
-
734
- class Request < Method(10, :request); end
735
-
736
- class Request
737
- table :meta_data
738
- end
739
-
740
- end
741
-
742
- class Test
743
-
744
- class Integer < Method(10, :integer); end
745
- class IntegerOk < Method(11, :integer_ok); end
746
- class String < Method(20, :string); end
747
- class StringOk < Method(21, :string_ok); end
748
- class Table < Method(30, :table); end
749
- class TableOk < Method(31, :table_ok); end
750
- class Content < Method(40, :content); end
751
- class ContentOk < Method(41, :content_ok); end
752
-
753
- class Integer
754
- octet :integer_1
755
- short :integer_2
756
- long :integer_3
757
- longlong :integer_4
758
- octet :operation
759
- end
760
-
761
- class IntegerOk
762
- longlong :result
763
- end
764
-
765
- class String
766
- shortstr :string_1
767
- longstr :string_2
768
- octet :operation
769
- end
770
-
771
- class StringOk
772
- longstr :result
773
- end
774
-
775
- class Table
776
- table :table
777
- octet :integer_op
778
- octet :string_op
779
- end
780
-
781
- class TableOk
782
- longlong :integer_result
783
- longstr :string_result
784
- end
785
-
786
- class Content
787
- end
788
-
789
- class ContentOk
790
- long :content_checksum
791
- end
792
-
793
- end
794
-
795
- end
796
- end