amqp-client 0.2.3 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/docs.yml +25 -0
- data/.rubocop.yml +12 -1
- data/.rubocop_todo.yml +14 -58
- data/.yardopts +1 -0
- data/CHANGELOG.md +40 -0
- data/README.md +8 -4
- data/lib/amqp/client/channel.rb +490 -247
- data/lib/amqp/client/connection.rb +421 -345
- data/lib/amqp/client/errors.rb +46 -25
- data/lib/amqp/client/exchange.rb +66 -0
- data/lib/amqp/client/frames.rb +526 -522
- data/lib/amqp/client/message.rb +48 -9
- data/lib/amqp/client/properties.rb +227 -192
- data/lib/amqp/client/queue.rb +72 -0
- data/lib/amqp/client/table.rb +118 -107
- data/lib/amqp/client/version.rb +2 -1
- data/lib/amqp/client.rb +170 -55
- metadata +7 -3
data/lib/amqp/client/errors.rb
CHANGED
@@ -2,40 +2,61 @@
|
|
2
2
|
|
3
3
|
module AMQP
|
4
4
|
class Client
|
5
|
-
|
5
|
+
# All errors raised inherit from this class
|
6
|
+
class Error < StandardError
|
7
|
+
# Raised when a frame that wasn't expected arrives
|
8
|
+
class UnexpectedFrame < Error
|
9
|
+
def initialize(expected, actual)
|
10
|
+
super "Expected frame type '#{expected}' but got '#{actual}'"
|
11
|
+
end
|
12
|
+
end
|
6
13
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
14
|
+
# Raised when a frame doesn't end with 206
|
15
|
+
class UnexpectedFrameEnd < Error
|
16
|
+
def initialize(actual)
|
17
|
+
super "Expected frame end 206 but got '#{actual}'"
|
18
|
+
end
|
11
19
|
end
|
12
|
-
end
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
# Should never be raised as we support all official frame types
|
22
|
+
class UnsupportedFrameType < Error
|
23
|
+
def initialize(type)
|
24
|
+
super "Unsupported frame type '#{type}'"
|
25
|
+
end
|
18
26
|
end
|
19
|
-
end
|
20
27
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
# Raised if a frame is received but not implemented
|
29
|
+
class UnsupportedMethodFrame < Error
|
30
|
+
def initialize(class_id, method_id)
|
31
|
+
super "Unsupported class/method: #{class_id} #{method_id}"
|
32
|
+
end
|
25
33
|
end
|
26
|
-
end
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
# Depending on close level a ConnectionClosed or ChannelClosed error is returned
|
36
|
+
class Closed < Error
|
37
|
+
def self.new(id, level, code, reason, classid = 0, methodid = 0)
|
38
|
+
case level
|
39
|
+
when :connection
|
40
|
+
ConnectionClosed.new(code, reason, classid, methodid)
|
41
|
+
when :channel
|
42
|
+
ChannelClosed.new(id, code, reason, classid, methodid)
|
43
|
+
else raise ArgumentError, "invalid level '#{level}'"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Raised if channel is already closed
|
49
|
+
class ChannelClosed < Error
|
50
|
+
def initialize(id, code, reason, classid = 0, methodid = 0)
|
51
|
+
super "Channel[#{id}] closed (#{code}) #{reason} (#{classid}/#{methodid})"
|
52
|
+
end
|
32
53
|
end
|
33
|
-
end
|
34
54
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
55
|
+
# Raised if connection is unexpectedly closed
|
56
|
+
class ConnectionClosed < Error
|
57
|
+
def initialize(code, reason, classid = 0, methodid = 0)
|
58
|
+
super "Connection closed (#{code}) #{reason} (#{classid}/#{methodid})"
|
59
|
+
end
|
39
60
|
end
|
40
61
|
end
|
41
62
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AMQP
|
4
|
+
class Client
|
5
|
+
# High level representation of an exchange
|
6
|
+
class Exchange
|
7
|
+
# Should only be initialized from the Client
|
8
|
+
# @api private
|
9
|
+
def initialize(client, name)
|
10
|
+
@client = client
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
# Publish to the exchange
|
15
|
+
# @param body [String] The message body
|
16
|
+
# @param routing_key [String] The routing key of the message,
|
17
|
+
# the exchange may use this when routing the message to bound queues
|
18
|
+
# @param properties [Properties]
|
19
|
+
# @option properties [String] content_type Content type of the message body
|
20
|
+
# @option properties [String] content_encoding Content encoding of the body
|
21
|
+
# @option properties [Hash<String, Object>] headers Custom headers
|
22
|
+
# @option properties [Integer] delivery_mode 2 for persisted message, transient messages for all other values
|
23
|
+
# @option properties [Integer] priority A priority of the message (between 0 and 255)
|
24
|
+
# @option properties [Integer] correlation_id A correlation id, most often used used for RPC communication
|
25
|
+
# @option properties [String] reply_to Queue to reply RPC responses to
|
26
|
+
# @option properties [Integer, String] expiration Number of seconds the message will stay in the queue
|
27
|
+
# @option properties [String] message_id Can be used to uniquely identify the message, e.g. for deduplication
|
28
|
+
# @option properties [Date] timestamp Often used for the time the message was originally generated
|
29
|
+
# @option properties [String] type Can indicate what kind of message this is
|
30
|
+
# @option properties [String] user_id Can be used to verify that this is the user that published the message
|
31
|
+
# @option properties [String] app_id Can be used to indicates which app that generated the message
|
32
|
+
# @return [Exchange] self
|
33
|
+
def publish(body, routing_key, **properties)
|
34
|
+
@client.publish(body, @name, routing_key, **properties)
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
# Bind to another exchange
|
39
|
+
# @param exchange [String] Name of the exchange to bind to
|
40
|
+
# @param binding_key [String] Binding key on which messages that match might be routed (depending on exchange type)
|
41
|
+
# @param arguments [Hash] Message headers to match on (only relevant for header exchanges)
|
42
|
+
# @return [Exchange] self
|
43
|
+
def bind(exchange, binding_key, arguments: {})
|
44
|
+
@client.exchange_bind(@name, exchange, binding_key, arguments: arguments)
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
# Unbind from another exchange
|
49
|
+
# @param exchange [String] Name of the exchange to unbind from
|
50
|
+
# @param binding_key [String] Binding key which the queue is bound to the exchange with
|
51
|
+
# @param arguments [Hash] Arguments matching the binding that's being removed
|
52
|
+
# @return [Exchange] self
|
53
|
+
def unbind(exchange, binding_key, arguments: {})
|
54
|
+
@client.exchange_unbind(@name, exchange, binding_key, arguments: arguments)
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
# Delete the exchange
|
59
|
+
# @return [nil]
|
60
|
+
def delete
|
61
|
+
@client.delete_exchange(@name)
|
62
|
+
nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/amqp/client/frames.rb
CHANGED
@@ -4,528 +4,532 @@ require_relative "./properties"
|
|
4
4
|
require_relative "./table"
|
5
5
|
|
6
6
|
module AMQP
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
1
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
1
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
1
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
1
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
1
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
1
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
1
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
1
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
7
|
+
class Client
|
8
|
+
# Generate binary data for different frames
|
9
|
+
# Each frame type implemented as a method
|
10
|
+
# Having a class for each frame type is more expensive in terms of CPU and memory
|
11
|
+
# @api private
|
12
|
+
module FrameBytes
|
13
|
+
module_function
|
14
|
+
|
15
|
+
def connection_start_ok(response, properties)
|
16
|
+
prop_tbl = Table.encode(properties)
|
17
|
+
[
|
18
|
+
1, # type: method
|
19
|
+
0, # channel id
|
20
|
+
2 + 2 + 4 + prop_tbl.bytesize + 6 + 4 + response.bytesize + 1, # frame size
|
21
|
+
10, # class id
|
22
|
+
11, # method id
|
23
|
+
prop_tbl.bytesize, prop_tbl, # client props
|
24
|
+
5, "PLAIN", # mechanism
|
25
|
+
response.bytesize, response,
|
26
|
+
0, "", # locale
|
27
|
+
206 # frame end
|
28
|
+
].pack("C S> L> S> S> L>a* Ca* L>a* Ca* C")
|
29
|
+
end
|
30
|
+
|
31
|
+
def connection_tune_ok(channel_max, frame_max, heartbeat)
|
32
|
+
[
|
33
|
+
1, # type: method
|
34
|
+
0, # channel id
|
35
|
+
12, # frame size
|
36
|
+
10, # class: connection
|
37
|
+
31, # method: tune-ok
|
38
|
+
channel_max,
|
39
|
+
frame_max,
|
40
|
+
heartbeat,
|
41
|
+
206 # frame end
|
42
|
+
].pack("CS>L>S>S>S>L>S>C")
|
43
|
+
end
|
44
|
+
|
45
|
+
def connection_open(vhost)
|
46
|
+
[
|
47
|
+
1, # type: method
|
48
|
+
0, # channel id
|
49
|
+
2 + 2 + 1 + vhost.bytesize + 1 + 1, # frame_size
|
50
|
+
10, # class: connection
|
51
|
+
40, # method: open
|
52
|
+
vhost.bytesize, vhost,
|
53
|
+
0, # reserved1
|
54
|
+
0, # reserved2
|
55
|
+
206 # frame end
|
56
|
+
].pack("C S> L> S> S> Ca* CCC")
|
57
|
+
end
|
58
|
+
|
59
|
+
def connection_close(code, reason)
|
60
|
+
frame_size = 2 + 2 + 2 + 1 + reason.bytesize + 2 + 2
|
61
|
+
[
|
62
|
+
1, # type: method
|
63
|
+
0, # channel id
|
64
|
+
frame_size, # frame size
|
65
|
+
10, # class: connection
|
66
|
+
50, # method: close
|
67
|
+
code,
|
68
|
+
reason.bytesize, reason,
|
69
|
+
0, # error class id
|
70
|
+
0, # error method id
|
71
|
+
206 # frame end
|
72
|
+
].pack("C S> L> S> S> S> Ca* S> S> C")
|
73
|
+
end
|
74
|
+
|
75
|
+
def connection_close_ok
|
76
|
+
[
|
77
|
+
1, # type: method
|
78
|
+
0, # channel id
|
79
|
+
4, # frame size
|
80
|
+
10, # class: connection
|
81
|
+
51, # method: close-ok
|
82
|
+
206 # frame end
|
83
|
+
].pack("C S> L> S> S> C")
|
84
|
+
end
|
85
|
+
|
86
|
+
def channel_open(id)
|
87
|
+
[
|
88
|
+
1, # type: method
|
89
|
+
id, # channel id
|
90
|
+
5, # frame size
|
91
|
+
20, # class: channel
|
92
|
+
10, # method: open
|
93
|
+
0, # reserved1
|
94
|
+
206 # frame end
|
95
|
+
].pack("C S> L> S> S> C C")
|
96
|
+
end
|
97
|
+
|
98
|
+
def channel_close(id, reason, code)
|
99
|
+
frame_size = 2 + 2 + 2 + 1 + reason.bytesize + 2 + 2
|
100
|
+
[
|
101
|
+
1, # type: method
|
102
|
+
id, # channel id
|
103
|
+
frame_size, # frame size
|
104
|
+
20, # class: channel
|
105
|
+
40, # method: close
|
106
|
+
code,
|
107
|
+
reason.bytesize, reason,
|
108
|
+
0, # error class id
|
109
|
+
0, # error method id
|
110
|
+
206 # frame end
|
111
|
+
].pack("C S> L> S> S> S> Ca* S> S> C")
|
112
|
+
end
|
113
|
+
|
114
|
+
def channel_close_ok(id)
|
115
|
+
[
|
116
|
+
1, # type: method
|
117
|
+
id, # channel id
|
118
|
+
4, # frame size
|
119
|
+
20, # class: channel
|
120
|
+
41, # method: close-ok
|
121
|
+
206 # frame end
|
122
|
+
].pack("C S> L> S> S> C")
|
123
|
+
end
|
124
|
+
|
125
|
+
def exchange_declare(id, name, type, passive, durable, auto_delete, internal, arguments)
|
126
|
+
no_wait = false
|
127
|
+
bits = 0
|
128
|
+
bits |= (1 << 0) if passive
|
129
|
+
bits |= (1 << 1) if durable
|
130
|
+
bits |= (1 << 2) if auto_delete
|
131
|
+
bits |= (1 << 3) if internal
|
132
|
+
bits |= (1 << 4) if no_wait
|
133
|
+
tbl = Table.encode(arguments)
|
134
|
+
frame_size = 2 + 2 + 2 + 1 + name.bytesize + 1 + type.bytesize + 1 + 4 + tbl.bytesize
|
135
|
+
[
|
136
|
+
1, # type: method
|
137
|
+
id, # channel id
|
138
|
+
frame_size, # frame size
|
139
|
+
40, # class: exchange
|
140
|
+
10, # method: declare
|
141
|
+
0, # reserved1
|
142
|
+
name.bytesize, name,
|
143
|
+
type.bytesize, type,
|
144
|
+
bits,
|
145
|
+
tbl.bytesize, tbl, # arguments
|
146
|
+
206 # frame end
|
147
|
+
].pack("C S> L> S> S> S> Ca* Ca* C L>a* C")
|
148
|
+
end
|
149
|
+
|
150
|
+
def exchange_delete(id, name, if_unused, no_wait)
|
151
|
+
bits = 0
|
152
|
+
bits |= (1 << 0) if if_unused
|
153
|
+
bits |= (1 << 1) if no_wait
|
154
|
+
frame_size = 2 + 2 + 2 + 1 + name.bytesize + 1
|
155
|
+
[
|
156
|
+
1, # type: method
|
157
|
+
id, # channel id
|
158
|
+
frame_size, # frame size
|
159
|
+
40, # class: exchange
|
160
|
+
20, # method: delete
|
161
|
+
0, # reserved1
|
162
|
+
name.bytesize, name,
|
163
|
+
bits,
|
164
|
+
206 # frame end
|
165
|
+
].pack("C S> L> S> S> S> Ca* C C")
|
166
|
+
end
|
167
|
+
|
168
|
+
def exchange_bind(id, destination, source, binding_key, no_wait, arguments)
|
169
|
+
tbl = Table.encode(arguments)
|
170
|
+
frame_size = 2 + 2 + 2 + 1 + destination.bytesize + 1 + source.bytesize + 1 +
|
171
|
+
binding_key.bytesize + 1 + 4 + tbl.bytesize
|
172
|
+
[
|
173
|
+
1, # type: method
|
174
|
+
id, # channel id
|
175
|
+
frame_size, # frame size
|
176
|
+
40, # class: exchange
|
177
|
+
30, # method: bind
|
178
|
+
0, # reserved1
|
179
|
+
destination.bytesize, destination,
|
180
|
+
source.bytesize, source,
|
181
|
+
binding_key.bytesize, binding_key,
|
182
|
+
no_wait ? 1 : 0,
|
183
|
+
tbl.bytesize, tbl, # arguments
|
184
|
+
206 # frame end
|
185
|
+
].pack("C S> L> S> S> S> Ca* Ca* Ca* C L>a* C")
|
186
|
+
end
|
187
|
+
|
188
|
+
def exchange_unbind(id, destination, source, binding_key, no_wait, arguments)
|
189
|
+
tbl = Table.encode(arguments)
|
190
|
+
frame_size = 2 + 2 + 2 + 1 + destination.bytesize + 1 + source.bytesize + 1 +
|
191
|
+
binding_key.bytesize + 1 + 4 + tbl.bytesize
|
192
|
+
[
|
193
|
+
1, # type: method
|
194
|
+
id, # channel id
|
195
|
+
frame_size, # frame size
|
196
|
+
40, # class: exchange
|
197
|
+
40, # method: unbind
|
198
|
+
0, # reserved1
|
199
|
+
destination.bytesize, destination,
|
200
|
+
source.bytesize, source,
|
201
|
+
binding_key.bytesize, binding_key,
|
202
|
+
no_wait ? 1 : 0,
|
203
|
+
tbl.bytesize, tbl, # arguments
|
204
|
+
206 # frame end
|
205
|
+
].pack("C S> L> S> S> S> Ca* Ca* Ca* C L>a* C")
|
206
|
+
end
|
207
|
+
|
208
|
+
def queue_declare(id, name, passive, durable, exclusive, auto_delete, arguments)
|
209
|
+
no_wait = false
|
210
|
+
bits = 0
|
211
|
+
bits |= (1 << 0) if passive
|
212
|
+
bits |= (1 << 1) if durable
|
213
|
+
bits |= (1 << 2) if exclusive
|
214
|
+
bits |= (1 << 3) if auto_delete
|
215
|
+
bits |= (1 << 4) if no_wait
|
216
|
+
tbl = Table.encode(arguments)
|
217
|
+
frame_size = 2 + 2 + 2 + 1 + name.bytesize + 1 + 4 + tbl.bytesize
|
218
|
+
[
|
219
|
+
1, # type: method
|
220
|
+
id, # channel id
|
221
|
+
frame_size, # frame size
|
222
|
+
50, # class: queue
|
223
|
+
10, # method: declare
|
224
|
+
0, # reserved1
|
225
|
+
name.bytesize, name,
|
226
|
+
bits,
|
227
|
+
tbl.bytesize, tbl, # arguments
|
228
|
+
206 # frame end
|
229
|
+
].pack("C S> L> S> S> S> Ca* C L>a* C")
|
230
|
+
end
|
231
|
+
|
232
|
+
def queue_delete(id, name, if_unused, if_empty, no_wait)
|
233
|
+
bits = 0
|
234
|
+
bits |= (1 << 0) if if_unused
|
235
|
+
bits |= (1 << 1) if if_empty
|
236
|
+
bits |= (1 << 2) if no_wait
|
237
|
+
frame_size = 2 + 2 + 2 + 1 + name.bytesize + 1
|
238
|
+
[
|
239
|
+
1, # type: method
|
240
|
+
id, # channel id
|
241
|
+
frame_size, # frame size
|
242
|
+
50, # class: queue
|
243
|
+
40, # method: declare
|
244
|
+
0, # reserved1
|
245
|
+
name.bytesize, name,
|
246
|
+
bits,
|
247
|
+
206 # frame end
|
248
|
+
].pack("C S> L> S> S> S> Ca* C C")
|
249
|
+
end
|
250
|
+
|
251
|
+
def queue_bind(id, queue, exchange, binding_key, no_wait, arguments)
|
252
|
+
tbl = Table.encode(arguments)
|
253
|
+
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1 + exchange.bytesize + 1 +
|
254
|
+
binding_key.bytesize + 1 + 4 + tbl.bytesize
|
255
|
+
[
|
256
|
+
1, # type: method
|
257
|
+
id, # channel id
|
258
|
+
frame_size, # frame size
|
259
|
+
50, # class: queue
|
260
|
+
20, # method: bind
|
261
|
+
0, # reserved1
|
262
|
+
queue.bytesize, queue,
|
263
|
+
exchange.bytesize, exchange,
|
264
|
+
binding_key.bytesize, binding_key,
|
265
|
+
no_wait ? 1 : 0,
|
266
|
+
tbl.bytesize, tbl, # arguments
|
267
|
+
206 # frame end
|
268
|
+
].pack("C S> L> S> S> S> Ca* Ca* Ca* C L>a* C")
|
269
|
+
end
|
270
|
+
|
271
|
+
def queue_unbind(id, queue, exchange, binding_key, arguments)
|
272
|
+
tbl = Table.encode(arguments)
|
273
|
+
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1 + exchange.bytesize + 1 +
|
274
|
+
binding_key.bytesize + 4 + tbl.bytesize
|
275
|
+
[
|
276
|
+
1, # type: method
|
277
|
+
id, # channel id
|
278
|
+
frame_size, # frame size
|
279
|
+
50, # class: queue
|
280
|
+
50, # method: unbind
|
281
|
+
0, # reserved1
|
282
|
+
queue.bytesize, queue,
|
283
|
+
exchange.bytesize, exchange,
|
284
|
+
binding_key.bytesize, binding_key,
|
285
|
+
tbl.bytesize, tbl, # arguments
|
286
|
+
206 # frame end
|
287
|
+
].pack("C S> L> S> S> S> Ca* Ca* Ca* L>a* C")
|
288
|
+
end
|
289
|
+
|
290
|
+
def queue_purge(id, queue, no_wait)
|
291
|
+
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1
|
292
|
+
[
|
293
|
+
1, # type: method
|
294
|
+
id, # channel id
|
295
|
+
frame_size, # frame size
|
296
|
+
50, # class: queue
|
297
|
+
30, # method: purge
|
298
|
+
0, # reserved1
|
299
|
+
queue.bytesize, queue,
|
300
|
+
no_wait ? 1 : 0,
|
301
|
+
206 # frame end
|
302
|
+
].pack("C S> L> S> S> S> Ca* C C")
|
303
|
+
end
|
304
|
+
|
305
|
+
def basic_get(id, queue, no_ack)
|
306
|
+
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1
|
307
|
+
[
|
308
|
+
1, # type: method
|
309
|
+
id, # channel id
|
310
|
+
frame_size, # frame size
|
311
|
+
60, # class: basic
|
312
|
+
70, # method: get
|
313
|
+
0, # reserved1
|
314
|
+
queue.bytesize, queue,
|
315
|
+
no_ack ? 1 : 0,
|
316
|
+
206 # frame end
|
317
|
+
].pack("C S> L> S> S> S> Ca* C C")
|
318
|
+
end
|
319
|
+
|
320
|
+
def basic_publish(id, exchange, routing_key, mandatory)
|
321
|
+
frame_size = 2 + 2 + 2 + 1 + exchange.bytesize + 1 + routing_key.bytesize + 1
|
322
|
+
[
|
323
|
+
1, # type: method
|
324
|
+
id, # channel id
|
325
|
+
frame_size, # frame size
|
326
|
+
60, # class: basic
|
327
|
+
40, # method: publish
|
328
|
+
0, # reserved1
|
329
|
+
exchange.bytesize, exchange,
|
330
|
+
routing_key.bytesize, routing_key,
|
331
|
+
mandatory ? 1 : 0, # bits, mandatory/immediate
|
332
|
+
206 # frame end
|
333
|
+
].pack("C S> L> S> S> S> Ca* Ca* C C")
|
334
|
+
end
|
335
|
+
|
336
|
+
def header(id, body_size, properties)
|
337
|
+
props = Properties.new(**properties).encode
|
338
|
+
frame_size = 2 + 2 + 8 + props.bytesize
|
339
|
+
[
|
340
|
+
2, # type: header
|
341
|
+
id, # channel id
|
342
|
+
frame_size, # frame size
|
343
|
+
60, # class: basic
|
344
|
+
0, # weight
|
345
|
+
body_size,
|
346
|
+
props, # properties
|
347
|
+
206 # frame end
|
348
|
+
].pack("C S> L> S> S> Q> a* C")
|
349
|
+
end
|
350
|
+
|
351
|
+
def body(id, body_part)
|
352
|
+
[
|
353
|
+
3, # type: body
|
354
|
+
id, # channel id
|
355
|
+
body_part.bytesize, # frame size
|
356
|
+
body_part,
|
357
|
+
206 # frame end
|
358
|
+
].pack("C S> L> a* C")
|
359
|
+
end
|
360
|
+
|
361
|
+
def basic_consume(id, queue, tag, no_ack, exclusive, arguments)
|
362
|
+
no_local = false
|
363
|
+
no_wait = false
|
364
|
+
bits = 0
|
365
|
+
bits |= (1 << 0) if no_local
|
366
|
+
bits |= (1 << 1) if no_ack
|
367
|
+
bits |= (1 << 2) if exclusive
|
368
|
+
bits |= (1 << 3) if no_wait
|
369
|
+
tbl = Table.encode(arguments)
|
370
|
+
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1 + tag.bytesize + 1 + 4 + tbl.bytesize
|
371
|
+
[
|
372
|
+
1, # type: method
|
373
|
+
id, # channel id
|
374
|
+
frame_size, # frame size
|
375
|
+
60, # class: basic
|
376
|
+
20, # method: consume
|
377
|
+
0, # reserved1
|
378
|
+
queue.bytesize, queue,
|
379
|
+
tag.bytesize, tag,
|
380
|
+
bits, # bits
|
381
|
+
tbl.bytesize, tbl, # arguments
|
382
|
+
206 # frame end
|
383
|
+
].pack("C S> L> S> S> S> Ca* Ca* C L>a* C")
|
384
|
+
end
|
385
|
+
|
386
|
+
def basic_cancel(id, consumer_tag, no_wait: false)
|
387
|
+
frame_size = 2 + 2 + 1 + consumer_tag.bytesize + 1
|
388
|
+
[
|
389
|
+
1, # type: method
|
390
|
+
id, # channel id
|
391
|
+
frame_size, # frame size
|
392
|
+
60, # class: basic
|
393
|
+
30, # method: cancel
|
394
|
+
consumer_tag.bytesize, consumer_tag,
|
395
|
+
no_wait ? 1 : 0,
|
396
|
+
206 # frame end
|
397
|
+
].pack("C S> L> S> S> Ca* C C")
|
398
|
+
end
|
399
|
+
|
400
|
+
def basic_cancel_ok(id, consumer_tag)
|
401
|
+
frame_size = 2 + 2 + 1 + consumer_tag.bytesize + 1
|
402
|
+
[
|
403
|
+
1, # type: method
|
404
|
+
id, # channel id
|
405
|
+
frame_size, # frame size
|
406
|
+
60, # class: basic
|
407
|
+
31, # method: cancel-ok
|
408
|
+
consumer_tag.bytesize, consumer_tag,
|
409
|
+
206 # frame end
|
410
|
+
].pack("C S> L> S> S> Ca* C")
|
411
|
+
end
|
412
|
+
|
413
|
+
def basic_ack(id, delivery_tag, multiple)
|
414
|
+
frame_size = 2 + 2 + 8 + 1
|
415
|
+
[
|
416
|
+
1, # type: method
|
417
|
+
id, # channel id
|
418
|
+
frame_size, # frame size
|
419
|
+
60, # class: basic
|
420
|
+
80, # method: ack
|
421
|
+
delivery_tag,
|
422
|
+
multiple ? 1 : 0,
|
423
|
+
206 # frame end
|
424
|
+
].pack("C S> L> S> S> Q> C C")
|
425
|
+
end
|
426
|
+
|
427
|
+
def basic_nack(id, delivery_tag, multiple, requeue)
|
428
|
+
bits = 0
|
429
|
+
bits |= (1 << 0) if multiple
|
430
|
+
bits |= (1 << 1) if requeue
|
431
|
+
frame_size = 2 + 2 + 8 + 1
|
432
|
+
[
|
433
|
+
1, # type: method
|
434
|
+
id, # channel id
|
435
|
+
frame_size, # frame size
|
436
|
+
60, # class: basic
|
437
|
+
120, # method: nack
|
438
|
+
delivery_tag,
|
439
|
+
bits,
|
440
|
+
206 # frame end
|
441
|
+
].pack("C S> L> S> S> Q> C C")
|
442
|
+
end
|
443
|
+
|
444
|
+
def basic_reject(id, delivery_tag, requeue)
|
445
|
+
frame_size = 2 + 2 + 8 + 1
|
446
|
+
[
|
447
|
+
1, # type: method
|
448
|
+
id, # channel id
|
449
|
+
frame_size, # frame size
|
450
|
+
60, # class: basic
|
451
|
+
90, # method: reject
|
452
|
+
delivery_tag,
|
453
|
+
requeue ? 1 : 0,
|
454
|
+
206 # frame end
|
455
|
+
].pack("C S> L> S> S> Q> C C")
|
456
|
+
end
|
457
|
+
|
458
|
+
def basic_qos(id, prefetch_size, prefetch_count, global)
|
459
|
+
frame_size = 2 + 2 + 4 + 2 + 1
|
460
|
+
[
|
461
|
+
1, # type: method
|
462
|
+
id, # channel id
|
463
|
+
frame_size, # frame size
|
464
|
+
60, # class: basic
|
465
|
+
10, # method: qos
|
466
|
+
prefetch_size,
|
467
|
+
prefetch_count,
|
468
|
+
global ? 1 : 0,
|
469
|
+
206 # frame end
|
470
|
+
].pack("C S> L> S> S> L> S> C C")
|
471
|
+
end
|
472
|
+
|
473
|
+
def basic_recover(id, requeue)
|
474
|
+
frame_size = 2 + 2 + 1
|
475
|
+
[
|
476
|
+
1, # type: method
|
477
|
+
id, # channel id
|
478
|
+
frame_size, # frame size
|
479
|
+
60, # class: basic
|
480
|
+
110, # method: recover
|
481
|
+
requeue ? 1 : 0,
|
482
|
+
206 # frame end
|
483
|
+
].pack("C S> L> S> S> C C")
|
484
|
+
end
|
485
|
+
|
486
|
+
def confirm_select(id, no_wait)
|
487
|
+
[
|
488
|
+
1, # type: method
|
489
|
+
id, # channel id
|
490
|
+
5, # frame size
|
491
|
+
85, # class: confirm
|
492
|
+
10, # method: select
|
493
|
+
no_wait ? 1 : 0,
|
494
|
+
206 # frame end
|
495
|
+
].pack("C S> L> S> S> C C")
|
496
|
+
end
|
497
|
+
|
498
|
+
def tx_select(id)
|
499
|
+
frame_size = 2 + 2
|
500
|
+
[
|
501
|
+
1, # type: method
|
502
|
+
id, # channel id
|
503
|
+
frame_size, # frame size
|
504
|
+
90, # class: tx
|
505
|
+
10, # method: select
|
506
|
+
206 # frame end
|
507
|
+
].pack("C S> L> S> S> C")
|
508
|
+
end
|
509
|
+
|
510
|
+
def tx_commit(id)
|
511
|
+
frame_size = 2 + 2
|
512
|
+
[
|
513
|
+
1, # type: method
|
514
|
+
id, # channel id
|
515
|
+
frame_size, # frame size
|
516
|
+
90, # class: tx
|
517
|
+
20, # method: commit
|
518
|
+
206 # frame end
|
519
|
+
].pack("C S> L> S> S> C")
|
520
|
+
end
|
521
|
+
|
522
|
+
def tx_rollback(id)
|
523
|
+
frame_size = 2 + 2
|
524
|
+
[
|
525
|
+
1, # type: method
|
526
|
+
id, # channel id
|
527
|
+
frame_size, # frame size
|
528
|
+
90, # class: tx
|
529
|
+
30, # method: rollback
|
530
|
+
206 # frame end
|
531
|
+
].pack("C S> L> S> S> C")
|
532
|
+
end
|
529
533
|
end
|
530
534
|
end
|
531
535
|
end
|