sparqcode_bunny 0.0.1
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.
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/.yardopts +9 -0
- data/CHANGELOG +27 -0
- data/Gemfile +39 -0
- data/LICENSE +21 -0
- data/README.textile +82 -0
- data/Rakefile +14 -0
- data/bunny.gemspec +43 -0
- data/examples/simple_08.rb +32 -0
- data/examples/simple_09.rb +32 -0
- data/examples/simple_ack_08.rb +35 -0
- data/examples/simple_ack_09.rb +35 -0
- data/examples/simple_consumer_08.rb +55 -0
- data/examples/simple_consumer_09.rb +55 -0
- data/examples/simple_fanout_08.rb +41 -0
- data/examples/simple_fanout_09.rb +41 -0
- data/examples/simple_headers_08.rb +42 -0
- data/examples/simple_headers_09.rb +42 -0
- data/examples/simple_publisher_08.rb +29 -0
- data/examples/simple_publisher_09.rb +29 -0
- data/examples/simple_topic_08.rb +61 -0
- data/examples/simple_topic_09.rb +61 -0
- data/ext/amqp-0.8.json +616 -0
- data/ext/amqp-0.9.1.json +388 -0
- data/ext/config.yml +4 -0
- data/ext/qparser.rb +469 -0
- data/lib/bunny/channel08.rb +39 -0
- data/lib/bunny/channel09.rb +39 -0
- data/lib/bunny/client08.rb +472 -0
- data/lib/bunny/client09.rb +374 -0
- data/lib/bunny/consumer.rb +35 -0
- data/lib/bunny/exchange08.rb +171 -0
- data/lib/bunny/exchange09.rb +159 -0
- data/lib/bunny/queue08.rb +403 -0
- data/lib/bunny/queue09.rb +325 -0
- data/lib/bunny/subscription08.rb +87 -0
- data/lib/bunny/subscription09.rb +87 -0
- data/lib/bunny/system_timer.rb +14 -0
- data/lib/bunny/version.rb +5 -0
- data/lib/bunny.rb +109 -0
- data/lib/qrack/amq-client-url.rb +165 -0
- data/lib/qrack/channel.rb +20 -0
- data/lib/qrack/client.rb +235 -0
- data/lib/qrack/errors.rb +5 -0
- data/lib/qrack/protocol/protocol08.rb +134 -0
- data/lib/qrack/protocol/protocol09.rb +135 -0
- data/lib/qrack/protocol/spec08.rb +828 -0
- data/lib/qrack/protocol/spec09.rb +524 -0
- data/lib/qrack/qrack08.rb +20 -0
- data/lib/qrack/qrack09.rb +20 -0
- data/lib/qrack/queue.rb +40 -0
- data/lib/qrack/subscription.rb +112 -0
- data/lib/qrack/transport/buffer08.rb +278 -0
- data/lib/qrack/transport/buffer09.rb +280 -0
- data/lib/qrack/transport/frame08.rb +117 -0
- data/lib/qrack/transport/frame09.rb +97 -0
- data/spec/spec_08/bunny_spec.rb +77 -0
- data/spec/spec_08/connection_spec.rb +25 -0
- data/spec/spec_08/exchange_spec.rb +173 -0
- data/spec/spec_08/queue_spec.rb +235 -0
- data/spec/spec_09/amqp_url_spec.rb +19 -0
- data/spec/spec_09/bunny_spec.rb +76 -0
- data/spec/spec_09/connection_spec.rb +29 -0
- data/spec/spec_09/exchange_spec.rb +173 -0
- data/spec/spec_09/queue_spec.rb +248 -0
- metadata +151 -0
@@ -0,0 +1,524 @@
|
|
1
|
+
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
|
5
|
+
#:stopdoc:
|
6
|
+
# this file was autogenerated on 2011-07-21 07:07:06 +0100
|
7
|
+
# using amqp-0.9.1.json (mtime: 2011-07-20 19:10:34 +0100)
|
8
|
+
#
|
9
|
+
# DO NOT EDIT! (edit ext/qparser.rb and config.yml instead, and run 'ruby qparser.rb')
|
10
|
+
|
11
|
+
module Qrack
|
12
|
+
module Protocol09
|
13
|
+
HEADER = "AMQP".freeze
|
14
|
+
VERSION_MAJOR = 0
|
15
|
+
VERSION_MINOR = 9
|
16
|
+
REVISION = 1
|
17
|
+
PORT = 5672
|
18
|
+
|
19
|
+
RESPONSES = {
|
20
|
+
200 => :REPLY_SUCCESS,
|
21
|
+
311 => :CONTENT_TOO_LARGE,
|
22
|
+
312 => :NO_ROUTE,
|
23
|
+
313 => :NO_CONSUMERS,
|
24
|
+
320 => :CONNECTION_FORCED,
|
25
|
+
402 => :INVALID_PATH,
|
26
|
+
403 => :ACCESS_REFUSED,
|
27
|
+
404 => :NOT_FOUND,
|
28
|
+
405 => :RESOURCE_LOCKED,
|
29
|
+
406 => :PRECONDITION_FAILED,
|
30
|
+
502 => :SYNTAX_ERROR,
|
31
|
+
503 => :COMMAND_INVALID,
|
32
|
+
504 => :CHANNEL_ERROR,
|
33
|
+
505 => :UNEXPECTED_FRAME,
|
34
|
+
506 => :RESOURCE_ERROR,
|
35
|
+
530 => :NOT_ALLOWED,
|
36
|
+
540 => :NOT_IMPLEMENTED,
|
37
|
+
541 => :INTERNAL_ERROR,
|
38
|
+
}
|
39
|
+
|
40
|
+
FIELDS = [
|
41
|
+
:bit,
|
42
|
+
:long,
|
43
|
+
:longlong,
|
44
|
+
:longstr,
|
45
|
+
:octet,
|
46
|
+
:short,
|
47
|
+
:shortstr,
|
48
|
+
:table,
|
49
|
+
:timestamp,
|
50
|
+
]
|
51
|
+
|
52
|
+
class Class
|
53
|
+
class << self
|
54
|
+
FIELDS.each do |f|
|
55
|
+
class_eval %[
|
56
|
+
def #{f} name
|
57
|
+
properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
|
58
|
+
attr_accessor name
|
59
|
+
end
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
63
|
+
def properties() @properties ||= [] end
|
64
|
+
|
65
|
+
def id() self::ID end
|
66
|
+
def name() self::NAME.to_s end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Method
|
70
|
+
class << self
|
71
|
+
FIELDS.each do |f|
|
72
|
+
class_eval %[
|
73
|
+
def #{f} name
|
74
|
+
arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
|
75
|
+
attr_accessor name
|
76
|
+
end
|
77
|
+
]
|
78
|
+
end
|
79
|
+
|
80
|
+
def arguments() @arguments ||= [] end
|
81
|
+
|
82
|
+
def parent() Protocol09.const_get(self.to_s[/Protocol09::(.+?)::/,1]) end
|
83
|
+
def id() self::ID end
|
84
|
+
def name() self::NAME.to_s end
|
85
|
+
end
|
86
|
+
|
87
|
+
def == b
|
88
|
+
self.class.arguments.inject(true) do |eql, (type, name)|
|
89
|
+
eql and __send__("#{name}") == b.__send__("#{name}")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.methods() @methods ||= {} end
|
95
|
+
|
96
|
+
def self.Method(id, name)
|
97
|
+
@_base_methods ||= {}
|
98
|
+
@_base_methods[id] ||= ::Class.new(Method) do
|
99
|
+
class_eval %[
|
100
|
+
def self.inherited klass
|
101
|
+
klass.const_set(:ID, #{id})
|
102
|
+
klass.const_set(:NAME, :#{name.to_s})
|
103
|
+
klass.parent.methods[#{id}] = klass
|
104
|
+
klass.parent.methods[klass::NAME] = klass
|
105
|
+
end
|
106
|
+
]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.classes() @classes ||= {} end
|
112
|
+
|
113
|
+
def self.Class(id, name)
|
114
|
+
@_base_classes ||= {}
|
115
|
+
@_base_classes[id] ||= ::Class.new(Class) do
|
116
|
+
class_eval %[
|
117
|
+
def self.inherited klass
|
118
|
+
klass.const_set(:ID, #{id})
|
119
|
+
klass.const_set(:NAME, :#{name.to_s})
|
120
|
+
Protocol09.classes[#{id}] = klass
|
121
|
+
Protocol09.classes[klass::NAME] = klass
|
122
|
+
end
|
123
|
+
]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
module Qrack
|
130
|
+
module Protocol09
|
131
|
+
class Connection < Class( 10, :connection ); end
|
132
|
+
class Channel < Class( 20, :channel ); end
|
133
|
+
class Exchange < Class( 40, :exchange ); end
|
134
|
+
class Queue < Class( 50, :queue ); end
|
135
|
+
class Basic < Class( 60, :basic ); end
|
136
|
+
class Tx < Class( 90, :tx ); 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 Close < Method( 50, :close ); end
|
149
|
+
class CloseOk < Method( 51, :close_ok ); end
|
150
|
+
|
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 :deprecated_capabilities
|
190
|
+
bit :deprecated_insist
|
191
|
+
end
|
192
|
+
|
193
|
+
class OpenOk
|
194
|
+
shortstr :deprecated_known_hosts
|
195
|
+
end
|
196
|
+
|
197
|
+
class Close
|
198
|
+
short :reply_code
|
199
|
+
shortstr :reply_text
|
200
|
+
short :class_id
|
201
|
+
short :method_id
|
202
|
+
end
|
203
|
+
|
204
|
+
class CloseOk
|
205
|
+
end
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
class Channel
|
210
|
+
|
211
|
+
class Open < Method( 10, :open ); end
|
212
|
+
class OpenOk < Method( 11, :open_ok ); end
|
213
|
+
class Flow < Method( 20, :flow ); end
|
214
|
+
class FlowOk < Method( 21, :flow_ok ); end
|
215
|
+
class Close < Method( 40, :close ); end
|
216
|
+
class CloseOk < Method( 41, :close_ok ); end
|
217
|
+
|
218
|
+
|
219
|
+
class Open
|
220
|
+
shortstr :deprecated_out_of_band
|
221
|
+
end
|
222
|
+
|
223
|
+
class OpenOk
|
224
|
+
longstr :deprecated_channel_id
|
225
|
+
end
|
226
|
+
|
227
|
+
class Flow
|
228
|
+
bit :active
|
229
|
+
end
|
230
|
+
|
231
|
+
class FlowOk
|
232
|
+
bit :active
|
233
|
+
end
|
234
|
+
|
235
|
+
class Close
|
236
|
+
short :reply_code
|
237
|
+
shortstr :reply_text
|
238
|
+
short :class_id
|
239
|
+
short :method_id
|
240
|
+
end
|
241
|
+
|
242
|
+
class CloseOk
|
243
|
+
end
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
class Exchange
|
248
|
+
|
249
|
+
class Declare < Method( 10, :declare ); end
|
250
|
+
class DeclareOk < Method( 11, :declare_ok ); end
|
251
|
+
class Delete < Method( 20, :delete ); end
|
252
|
+
class DeleteOk < Method( 21, :delete_ok ); end
|
253
|
+
|
254
|
+
|
255
|
+
class Declare
|
256
|
+
short :deprecated_ticket
|
257
|
+
shortstr :exchange
|
258
|
+
shortstr :type
|
259
|
+
bit :passive
|
260
|
+
bit :durable
|
261
|
+
bit :deprecated_auto_delete
|
262
|
+
bit :deprecated_internal
|
263
|
+
bit :nowait
|
264
|
+
table :arguments
|
265
|
+
end
|
266
|
+
|
267
|
+
class DeclareOk
|
268
|
+
end
|
269
|
+
|
270
|
+
class Delete
|
271
|
+
short :deprecated_ticket
|
272
|
+
shortstr :exchange
|
273
|
+
bit :if_unused
|
274
|
+
bit :nowait
|
275
|
+
end
|
276
|
+
|
277
|
+
class DeleteOk
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
class Queue
|
283
|
+
|
284
|
+
class Declare < Method( 10, :declare ); end
|
285
|
+
class DeclareOk < Method( 11, :declare_ok ); end
|
286
|
+
class Bind < Method( 20, :bind ); end
|
287
|
+
class BindOk < Method( 21, :bind_ok ); end
|
288
|
+
class Purge < Method( 30, :purge ); end
|
289
|
+
class PurgeOk < Method( 31, :purge_ok ); end
|
290
|
+
class Delete < Method( 40, :delete ); end
|
291
|
+
class DeleteOk < Method( 41, :delete_ok ); end
|
292
|
+
class Unbind < Method( 50, :unbind ); end
|
293
|
+
class UnbindOk < Method( 51, :unbind_ok ); end
|
294
|
+
|
295
|
+
|
296
|
+
class Declare
|
297
|
+
short :deprecated_ticket
|
298
|
+
shortstr :queue
|
299
|
+
bit :passive
|
300
|
+
bit :durable
|
301
|
+
bit :exclusive
|
302
|
+
bit :auto_delete
|
303
|
+
bit :nowait
|
304
|
+
table :arguments
|
305
|
+
end
|
306
|
+
|
307
|
+
class DeclareOk
|
308
|
+
shortstr :queue
|
309
|
+
long :message_count
|
310
|
+
long :consumer_count
|
311
|
+
end
|
312
|
+
|
313
|
+
class Bind
|
314
|
+
short :deprecated_ticket
|
315
|
+
shortstr :queue
|
316
|
+
shortstr :exchange
|
317
|
+
shortstr :routing_key
|
318
|
+
bit :nowait
|
319
|
+
table :arguments
|
320
|
+
end
|
321
|
+
|
322
|
+
class BindOk
|
323
|
+
end
|
324
|
+
|
325
|
+
class Purge
|
326
|
+
short :deprecated_ticket
|
327
|
+
shortstr :queue
|
328
|
+
bit :nowait
|
329
|
+
end
|
330
|
+
|
331
|
+
class PurgeOk
|
332
|
+
long :message_count
|
333
|
+
end
|
334
|
+
|
335
|
+
class Delete
|
336
|
+
short :deprecated_ticket
|
337
|
+
shortstr :queue
|
338
|
+
bit :if_unused
|
339
|
+
bit :if_empty
|
340
|
+
bit :nowait
|
341
|
+
end
|
342
|
+
|
343
|
+
class DeleteOk
|
344
|
+
long :message_count
|
345
|
+
end
|
346
|
+
|
347
|
+
class Unbind
|
348
|
+
short :deprecated_ticket
|
349
|
+
shortstr :queue
|
350
|
+
shortstr :exchange
|
351
|
+
shortstr :routing_key
|
352
|
+
table :arguments
|
353
|
+
end
|
354
|
+
|
355
|
+
class UnbindOk
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
|
360
|
+
class Basic
|
361
|
+
shortstr :content_type
|
362
|
+
shortstr :content_encoding
|
363
|
+
table :headers
|
364
|
+
octet :delivery_mode
|
365
|
+
octet :priority
|
366
|
+
shortstr :correlation_id
|
367
|
+
shortstr :reply_to
|
368
|
+
shortstr :expiration
|
369
|
+
shortstr :message_id
|
370
|
+
timestamp :timestamp
|
371
|
+
shortstr :type
|
372
|
+
shortstr :user_id
|
373
|
+
shortstr :app_id
|
374
|
+
shortstr :deprecated_cluster_id
|
375
|
+
|
376
|
+
class Qos < Method( 10, :qos ); end
|
377
|
+
class QosOk < Method( 11, :qos_ok ); end
|
378
|
+
class Consume < Method( 20, :consume ); end
|
379
|
+
class ConsumeOk < Method( 21, :consume_ok ); end
|
380
|
+
class Cancel < Method( 30, :cancel ); end
|
381
|
+
class CancelOk < Method( 31, :cancel_ok ); end
|
382
|
+
class Publish < Method( 40, :publish ); end
|
383
|
+
class Return < Method( 50, :return ); end
|
384
|
+
class Deliver < Method( 60, :deliver ); end
|
385
|
+
class Get < Method( 70, :get ); end
|
386
|
+
class GetOk < Method( 71, :get_ok ); end
|
387
|
+
class GetEmpty < Method( 72, :get_empty ); end
|
388
|
+
class Ack < Method( 80, :ack ); end
|
389
|
+
class Reject < Method( 90, :reject ); end
|
390
|
+
class RecoverAsync < Method( 100, :recover_async ); end
|
391
|
+
class Recover < Method( 110, :recover ); end
|
392
|
+
class RecoverOk < Method( 111, :recover_ok ); end
|
393
|
+
|
394
|
+
|
395
|
+
class Qos
|
396
|
+
long :prefetch_size
|
397
|
+
short :prefetch_count
|
398
|
+
bit :global
|
399
|
+
end
|
400
|
+
|
401
|
+
class QosOk
|
402
|
+
end
|
403
|
+
|
404
|
+
class Consume
|
405
|
+
short :deprecated_ticket
|
406
|
+
shortstr :queue
|
407
|
+
shortstr :consumer_tag
|
408
|
+
bit :no_local
|
409
|
+
bit :no_ack
|
410
|
+
bit :exclusive
|
411
|
+
bit :nowait
|
412
|
+
table :filter
|
413
|
+
end
|
414
|
+
|
415
|
+
class ConsumeOk
|
416
|
+
shortstr :consumer_tag
|
417
|
+
end
|
418
|
+
|
419
|
+
class Cancel
|
420
|
+
shortstr :consumer_tag
|
421
|
+
bit :nowait
|
422
|
+
end
|
423
|
+
|
424
|
+
class CancelOk
|
425
|
+
shortstr :consumer_tag
|
426
|
+
end
|
427
|
+
|
428
|
+
class Publish
|
429
|
+
short :deprecated_ticket
|
430
|
+
shortstr :exchange
|
431
|
+
shortstr :routing_key
|
432
|
+
bit :mandatory
|
433
|
+
bit :immediate
|
434
|
+
end
|
435
|
+
|
436
|
+
class Return
|
437
|
+
short :reply_code
|
438
|
+
shortstr :reply_text
|
439
|
+
shortstr :exchange
|
440
|
+
shortstr :routing_key
|
441
|
+
end
|
442
|
+
|
443
|
+
class Deliver
|
444
|
+
shortstr :consumer_tag
|
445
|
+
longlong :delivery_tag
|
446
|
+
bit :redelivered
|
447
|
+
shortstr :exchange
|
448
|
+
shortstr :routing_key
|
449
|
+
end
|
450
|
+
|
451
|
+
class Get
|
452
|
+
short :deprecated_ticket
|
453
|
+
shortstr :queue
|
454
|
+
bit :no_ack
|
455
|
+
end
|
456
|
+
|
457
|
+
class GetOk
|
458
|
+
longlong :delivery_tag
|
459
|
+
bit :redelivered
|
460
|
+
shortstr :exchange
|
461
|
+
shortstr :routing_key
|
462
|
+
long :message_count
|
463
|
+
end
|
464
|
+
|
465
|
+
class GetEmpty
|
466
|
+
shortstr :deprecated_cluster_id
|
467
|
+
end
|
468
|
+
|
469
|
+
class Ack
|
470
|
+
longlong :delivery_tag
|
471
|
+
bit :multiple
|
472
|
+
end
|
473
|
+
|
474
|
+
class Reject
|
475
|
+
longlong :delivery_tag
|
476
|
+
bit :requeue
|
477
|
+
end
|
478
|
+
|
479
|
+
class RecoverAsync
|
480
|
+
bit :requeue
|
481
|
+
end
|
482
|
+
|
483
|
+
class Recover
|
484
|
+
bit :requeue
|
485
|
+
end
|
486
|
+
|
487
|
+
class RecoverOk
|
488
|
+
end
|
489
|
+
|
490
|
+
end
|
491
|
+
|
492
|
+
class Tx
|
493
|
+
|
494
|
+
class Select < Method( 10, :select ); end
|
495
|
+
class SelectOk < Method( 11, :select_ok ); end
|
496
|
+
class Commit < Method( 20, :commit ); end
|
497
|
+
class CommitOk < Method( 21, :commit_ok ); end
|
498
|
+
class Rollback < Method( 30, :rollback ); end
|
499
|
+
class RollbackOk < Method( 31, :rollback_ok ); end
|
500
|
+
|
501
|
+
|
502
|
+
class Select
|
503
|
+
end
|
504
|
+
|
505
|
+
class SelectOk
|
506
|
+
end
|
507
|
+
|
508
|
+
class Commit
|
509
|
+
end
|
510
|
+
|
511
|
+
class CommitOk
|
512
|
+
end
|
513
|
+
|
514
|
+
class Rollback
|
515
|
+
end
|
516
|
+
|
517
|
+
class RollbackOk
|
518
|
+
end
|
519
|
+
|
520
|
+
end
|
521
|
+
|
522
|
+
end
|
523
|
+
|
524
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'protocol/spec08'
|
6
|
+
require 'protocol/protocol08'
|
7
|
+
|
8
|
+
require 'transport/buffer08'
|
9
|
+
require 'transport/frame08'
|
10
|
+
|
11
|
+
require 'qrack/client'
|
12
|
+
require 'qrack/channel'
|
13
|
+
require 'qrack/queue'
|
14
|
+
require 'bunny/consumer'
|
15
|
+
require 'qrack/errors'
|
16
|
+
|
17
|
+
module Qrack
|
18
|
+
include Protocol
|
19
|
+
include Transport
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'protocol/spec09'
|
6
|
+
require 'protocol/protocol09'
|
7
|
+
|
8
|
+
require 'transport/buffer09'
|
9
|
+
require 'transport/frame09'
|
10
|
+
|
11
|
+
require 'qrack/client'
|
12
|
+
require 'qrack/channel'
|
13
|
+
require 'qrack/queue'
|
14
|
+
require 'bunny/consumer'
|
15
|
+
require 'qrack/errors'
|
16
|
+
|
17
|
+
module Qrack
|
18
|
+
include Protocol09
|
19
|
+
include Transport09
|
20
|
+
end
|
data/lib/qrack/queue.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Qrack
|
4
|
+
|
5
|
+
# Queue ancestor class
|
6
|
+
class Queue
|
7
|
+
|
8
|
+
# @return [AMQ::Client::Consumer] Default consumer (registered with {Queue#subscribe}).
|
9
|
+
attr_accessor :default_consumer
|
10
|
+
|
11
|
+
attr_reader :name, :client
|
12
|
+
|
13
|
+
attr_accessor :delivery_tag
|
14
|
+
|
15
|
+
|
16
|
+
# Returns consumer count from {Queue#status}.
|
17
|
+
def consumer_count
|
18
|
+
s = status
|
19
|
+
s[:consumer_count]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns message count from {Queue#status}.
|
23
|
+
def message_count
|
24
|
+
s = status
|
25
|
+
s[:message_count]
|
26
|
+
end
|
27
|
+
|
28
|
+
# Publishes a message to the queue via the default nameless '' direct exchange.
|
29
|
+
|
30
|
+
# @return [NilClass] nil
|
31
|
+
# @deprecated
|
32
|
+
# @note This method will be removed before 0.8 release.
|
33
|
+
def publish(data, opts = {})
|
34
|
+
Bunny.deprecation_warning("Qrack::Queue#publish", "0.8", "Use direct_exchange = bunny.exchange(''); direct_exchange.publish('message', key: queue.name) if you want to publish directly to one given queue. For more informations see https://github.com/ruby-amqp/bunny/issues/15 and for more theoretical explanation check http://bit.ly/nOF1CK")
|
35
|
+
exchange.publish(data, opts)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#################################################
|
4
|
+
# WARNING: THIS CLASS IS DEPRECATED, DO NOT #
|
5
|
+
# USE IT DIRECTLY! USE BUNNY::CONSUMER INSTEAD! #
|
6
|
+
#################################################
|
7
|
+
|
8
|
+
module Qrack
|
9
|
+
# Subscription ancestor class
|
10
|
+
# @deprecated
|
11
|
+
class Subscription
|
12
|
+
|
13
|
+
attr_accessor :consumer_tag, :delivery_tag, :message_max, :timeout, :ack, :exclusive, :break_when_empty
|
14
|
+
attr_reader :client, :queue, :message_count
|
15
|
+
|
16
|
+
def initialize(client, queue, opts = {})
|
17
|
+
@client = client
|
18
|
+
@queue = queue
|
19
|
+
|
20
|
+
# Get timeout value
|
21
|
+
@timeout = opts[:timeout] || nil
|
22
|
+
|
23
|
+
# Get maximum amount of messages to process
|
24
|
+
@message_max = opts[:message_max] || nil
|
25
|
+
|
26
|
+
# If a consumer tag is not passed in the server will generate one
|
27
|
+
@consumer_tag = opts[:consumer_tag] || nil
|
28
|
+
|
29
|
+
# In a subscription loop, stop listening if there are no more messages in the queue
|
30
|
+
@break_when_empty = opts[:break_when_empty] || nil
|
31
|
+
|
32
|
+
# Ignore the :nowait option if passed, otherwise program will hang waiting for a
|
33
|
+
# response from the server causing an error.
|
34
|
+
opts.delete(:nowait)
|
35
|
+
|
36
|
+
# Do we want to have to provide an acknowledgement?
|
37
|
+
@ack = opts[:ack] || nil
|
38
|
+
|
39
|
+
# Does this consumer want exclusive use of the queue?
|
40
|
+
@exclusive = opts[:exclusive] || false
|
41
|
+
|
42
|
+
# Initialize message counter
|
43
|
+
@message_count = 0
|
44
|
+
|
45
|
+
# Store options
|
46
|
+
@opts = opts
|
47
|
+
end
|
48
|
+
|
49
|
+
def start(&blk)
|
50
|
+
# Do not process any messages if zero message_max
|
51
|
+
if message_max == 0
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
55
|
+
# Notify server about new consumer
|
56
|
+
setup_consumer
|
57
|
+
|
58
|
+
# Start subscription loop
|
59
|
+
loop do
|
60
|
+
|
61
|
+
begin
|
62
|
+
method = client.next_method(:timeout => timeout)
|
63
|
+
rescue Qrack::FrameTimeout
|
64
|
+
# Stop consuming messages
|
65
|
+
queue.unsubscribe()
|
66
|
+
break
|
67
|
+
end
|
68
|
+
|
69
|
+
# Increment message counter
|
70
|
+
@message_count += 1
|
71
|
+
|
72
|
+
# get delivery tag to use for acknowledge
|
73
|
+
queue.delivery_tag = method.delivery_tag if @ack
|
74
|
+
|
75
|
+
header = client.next_payload
|
76
|
+
|
77
|
+
# If maximum frame size is smaller than message payload body then message
|
78
|
+
# will have a message header and several message bodies
|
79
|
+
msg = ''
|
80
|
+
while msg.length < header.size
|
81
|
+
msg << client.next_payload
|
82
|
+
end
|
83
|
+
|
84
|
+
# If block present, pass the message info to the block for processing
|
85
|
+
msg = {:header => header, :payload => msg, :delivery_details => method.arguments, :subscribed => true}
|
86
|
+
blk.call(msg) unless blk.nil?
|
87
|
+
|
88
|
+
# Exit loop if message_max condition met
|
89
|
+
if (!message_max.nil? and message_count == message_max)
|
90
|
+
# Stop consuming messages
|
91
|
+
queue.unsubscribe()
|
92
|
+
queue.ack() if @ack
|
93
|
+
break
|
94
|
+
elsif(!msg[:subscribed])
|
95
|
+
queue.unsubscribe()
|
96
|
+
queue.ack() if @ack
|
97
|
+
break
|
98
|
+
elsif(@break_when_empty && queue.message_count == 0)
|
99
|
+
queue.unsubscribe()
|
100
|
+
queue.ack() if @ack
|
101
|
+
break
|
102
|
+
end
|
103
|
+
|
104
|
+
# Have to do the ack here because the ack triggers the release of messages from the server
|
105
|
+
# if you are using Client#qos prefetch and you will get extra messages sent through before
|
106
|
+
# the unsubscribe takes effect to stop messages being sent to this consumer unless the ack is
|
107
|
+
# deferred.
|
108
|
+
queue.ack() if @ack
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|