amqp-client 1.0.1 → 1.1.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/main.yml +2 -2
- data/.rubocop.yml +1 -1
- data/.rubocop_todo.yml +29 -12
- data/CHANGELOG.md +21 -0
- data/Gemfile +4 -0
- data/README.md +63 -28
- data/Rakefile +3 -1
- data/amqp-client.gemspec +1 -1
- data/lib/amqp/client/channel.rb +39 -32
- data/lib/amqp/client/connection.rb +107 -64
- data/lib/amqp/client/errors.rb +18 -1
- data/lib/amqp/client/{frames.rb → frame_bytes.rb} +34 -36
- data/lib/amqp/client/message.rb +101 -44
- data/lib/amqp/client/properties.rb +143 -76
- data/lib/amqp/client/queue.rb +15 -21
- data/lib/amqp/client/table.rb +51 -32
- data/lib/amqp/client/version.rb +1 -1
- data/lib/amqp/client.rb +27 -9
- data/sig/amqp-client.rbs +264 -0
- metadata +5 -4
@@ -10,9 +10,7 @@ module AMQP
|
|
10
10
|
# Having a class for each frame type is more expensive in terms of CPU and memory
|
11
11
|
# @api private
|
12
12
|
module FrameBytes
|
13
|
-
|
14
|
-
|
15
|
-
def connection_start_ok(response, properties)
|
13
|
+
def self.connection_start_ok(response, properties)
|
16
14
|
prop_tbl = Table.encode(properties)
|
17
15
|
[
|
18
16
|
1, # type: method
|
@@ -28,7 +26,7 @@ module AMQP
|
|
28
26
|
].pack("C S> L> S> S> L>a* Ca* L>a* Ca* C")
|
29
27
|
end
|
30
28
|
|
31
|
-
def connection_tune_ok(channel_max, frame_max, heartbeat)
|
29
|
+
def self.connection_tune_ok(channel_max, frame_max, heartbeat)
|
32
30
|
[
|
33
31
|
1, # type: method
|
34
32
|
0, # channel id
|
@@ -42,7 +40,7 @@ module AMQP
|
|
42
40
|
].pack("CS>L>S>S>S>L>S>C")
|
43
41
|
end
|
44
42
|
|
45
|
-
def connection_open(vhost)
|
43
|
+
def self.connection_open(vhost)
|
46
44
|
[
|
47
45
|
1, # type: method
|
48
46
|
0, # channel id
|
@@ -56,7 +54,7 @@ module AMQP
|
|
56
54
|
].pack("C S> L> S> S> Ca* CCC")
|
57
55
|
end
|
58
56
|
|
59
|
-
def connection_close(code, reason)
|
57
|
+
def self.connection_close(code, reason)
|
60
58
|
frame_size = 2 + 2 + 2 + 1 + reason.bytesize + 2 + 2
|
61
59
|
[
|
62
60
|
1, # type: method
|
@@ -72,7 +70,7 @@ module AMQP
|
|
72
70
|
].pack("C S> L> S> S> S> Ca* S> S> C")
|
73
71
|
end
|
74
72
|
|
75
|
-
def connection_close_ok
|
73
|
+
def self.connection_close_ok
|
76
74
|
[
|
77
75
|
1, # type: method
|
78
76
|
0, # channel id
|
@@ -83,7 +81,7 @@ module AMQP
|
|
83
81
|
].pack("C S> L> S> S> C")
|
84
82
|
end
|
85
83
|
|
86
|
-
def channel_open(id)
|
84
|
+
def self.channel_open(id)
|
87
85
|
[
|
88
86
|
1, # type: method
|
89
87
|
id, # channel id
|
@@ -95,7 +93,7 @@ module AMQP
|
|
95
93
|
].pack("C S> L> S> S> C C")
|
96
94
|
end
|
97
95
|
|
98
|
-
def channel_close(id, reason, code)
|
96
|
+
def self.channel_close(id, reason, code)
|
99
97
|
frame_size = 2 + 2 + 2 + 1 + reason.bytesize + 2 + 2
|
100
98
|
[
|
101
99
|
1, # type: method
|
@@ -111,7 +109,7 @@ module AMQP
|
|
111
109
|
].pack("C S> L> S> S> S> Ca* S> S> C")
|
112
110
|
end
|
113
111
|
|
114
|
-
def channel_close_ok(id)
|
112
|
+
def self.channel_close_ok(id)
|
115
113
|
[
|
116
114
|
1, # type: method
|
117
115
|
id, # channel id
|
@@ -122,7 +120,7 @@ module AMQP
|
|
122
120
|
].pack("C S> L> S> S> C")
|
123
121
|
end
|
124
122
|
|
125
|
-
def exchange_declare(id, name, type, passive, durable, auto_delete, internal, arguments)
|
123
|
+
def self.exchange_declare(id, name, type, passive, durable, auto_delete, internal, arguments)
|
126
124
|
no_wait = false
|
127
125
|
bits = 0
|
128
126
|
bits |= (1 << 0) if passive
|
@@ -147,7 +145,7 @@ module AMQP
|
|
147
145
|
].pack("C S> L> S> S> S> Ca* Ca* C L>a* C")
|
148
146
|
end
|
149
147
|
|
150
|
-
def exchange_delete(id, name, if_unused, no_wait)
|
148
|
+
def self.exchange_delete(id, name, if_unused, no_wait)
|
151
149
|
bits = 0
|
152
150
|
bits |= (1 << 0) if if_unused
|
153
151
|
bits |= (1 << 1) if no_wait
|
@@ -165,7 +163,7 @@ module AMQP
|
|
165
163
|
].pack("C S> L> S> S> S> Ca* C C")
|
166
164
|
end
|
167
165
|
|
168
|
-
def exchange_bind(id, destination, source, binding_key, no_wait, arguments)
|
166
|
+
def self.exchange_bind(id, destination, source, binding_key, no_wait, arguments)
|
169
167
|
tbl = Table.encode(arguments)
|
170
168
|
frame_size = 2 + 2 + 2 + 1 + destination.bytesize + 1 + source.bytesize + 1 +
|
171
169
|
binding_key.bytesize + 1 + 4 + tbl.bytesize
|
@@ -185,7 +183,7 @@ module AMQP
|
|
185
183
|
].pack("C S> L> S> S> S> Ca* Ca* Ca* C L>a* C")
|
186
184
|
end
|
187
185
|
|
188
|
-
def exchange_unbind(id, destination, source, binding_key, no_wait, arguments)
|
186
|
+
def self.exchange_unbind(id, destination, source, binding_key, no_wait, arguments)
|
189
187
|
tbl = Table.encode(arguments)
|
190
188
|
frame_size = 2 + 2 + 2 + 1 + destination.bytesize + 1 + source.bytesize + 1 +
|
191
189
|
binding_key.bytesize + 1 + 4 + tbl.bytesize
|
@@ -205,7 +203,7 @@ module AMQP
|
|
205
203
|
].pack("C S> L> S> S> S> Ca* Ca* Ca* C L>a* C")
|
206
204
|
end
|
207
205
|
|
208
|
-
def queue_declare(id, name, passive, durable, exclusive, auto_delete, arguments)
|
206
|
+
def self.queue_declare(id, name, passive, durable, exclusive, auto_delete, arguments)
|
209
207
|
no_wait = false
|
210
208
|
bits = 0
|
211
209
|
bits |= (1 << 0) if passive
|
@@ -229,7 +227,7 @@ module AMQP
|
|
229
227
|
].pack("C S> L> S> S> S> Ca* C L>a* C")
|
230
228
|
end
|
231
229
|
|
232
|
-
def queue_delete(id, name, if_unused, if_empty, no_wait)
|
230
|
+
def self.queue_delete(id, name, if_unused, if_empty, no_wait)
|
233
231
|
bits = 0
|
234
232
|
bits |= (1 << 0) if if_unused
|
235
233
|
bits |= (1 << 1) if if_empty
|
@@ -248,7 +246,7 @@ module AMQP
|
|
248
246
|
].pack("C S> L> S> S> S> Ca* C C")
|
249
247
|
end
|
250
248
|
|
251
|
-
def queue_bind(id, queue, exchange, binding_key, no_wait, arguments)
|
249
|
+
def self.queue_bind(id, queue, exchange, binding_key, no_wait, arguments)
|
252
250
|
tbl = Table.encode(arguments)
|
253
251
|
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1 + exchange.bytesize + 1 +
|
254
252
|
binding_key.bytesize + 1 + 4 + tbl.bytesize
|
@@ -268,7 +266,7 @@ module AMQP
|
|
268
266
|
].pack("C S> L> S> S> S> Ca* Ca* Ca* C L>a* C")
|
269
267
|
end
|
270
268
|
|
271
|
-
def queue_unbind(id, queue, exchange, binding_key, arguments)
|
269
|
+
def self.queue_unbind(id, queue, exchange, binding_key, arguments)
|
272
270
|
tbl = Table.encode(arguments)
|
273
271
|
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1 + exchange.bytesize + 1 +
|
274
272
|
binding_key.bytesize + 4 + tbl.bytesize
|
@@ -287,7 +285,7 @@ module AMQP
|
|
287
285
|
].pack("C S> L> S> S> S> Ca* Ca* Ca* L>a* C")
|
288
286
|
end
|
289
287
|
|
290
|
-
def queue_purge(id, queue, no_wait)
|
288
|
+
def self.queue_purge(id, queue, no_wait)
|
291
289
|
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1
|
292
290
|
[
|
293
291
|
1, # type: method
|
@@ -302,7 +300,7 @@ module AMQP
|
|
302
300
|
].pack("C S> L> S> S> S> Ca* C C")
|
303
301
|
end
|
304
302
|
|
305
|
-
def basic_get(id, queue, no_ack)
|
303
|
+
def self.basic_get(id, queue, no_ack)
|
306
304
|
frame_size = 2 + 2 + 2 + 1 + queue.bytesize + 1
|
307
305
|
[
|
308
306
|
1, # type: method
|
@@ -317,7 +315,7 @@ module AMQP
|
|
317
315
|
].pack("C S> L> S> S> S> Ca* C C")
|
318
316
|
end
|
319
317
|
|
320
|
-
def basic_publish(id, exchange, routing_key, mandatory)
|
318
|
+
def self.basic_publish(id, exchange, routing_key, mandatory)
|
321
319
|
frame_size = 2 + 2 + 2 + 1 + exchange.bytesize + 1 + routing_key.bytesize + 1
|
322
320
|
[
|
323
321
|
1, # type: method
|
@@ -333,8 +331,8 @@ module AMQP
|
|
333
331
|
].pack("C S> L> S> S> S> Ca* Ca* C C")
|
334
332
|
end
|
335
333
|
|
336
|
-
def header(id, body_size, properties)
|
337
|
-
props = Properties.
|
334
|
+
def self.header(id, body_size, properties)
|
335
|
+
props = Properties.encode(properties)
|
338
336
|
frame_size = 2 + 2 + 8 + props.bytesize
|
339
337
|
[
|
340
338
|
2, # type: header
|
@@ -348,7 +346,7 @@ module AMQP
|
|
348
346
|
].pack("C S> L> S> S> Q> a* C")
|
349
347
|
end
|
350
348
|
|
351
|
-
def body(id, body_part)
|
349
|
+
def self.body(id, body_part)
|
352
350
|
[
|
353
351
|
3, # type: body
|
354
352
|
id, # channel id
|
@@ -358,7 +356,7 @@ module AMQP
|
|
358
356
|
].pack("C S> L> a* C")
|
359
357
|
end
|
360
358
|
|
361
|
-
def basic_consume(id, queue, tag, no_ack, exclusive, arguments)
|
359
|
+
def self.basic_consume(id, queue, tag, no_ack, exclusive, arguments)
|
362
360
|
no_local = false
|
363
361
|
no_wait = false
|
364
362
|
bits = 0
|
@@ -383,7 +381,7 @@ module AMQP
|
|
383
381
|
].pack("C S> L> S> S> S> Ca* Ca* C L>a* C")
|
384
382
|
end
|
385
383
|
|
386
|
-
def basic_cancel(id, consumer_tag, no_wait: false)
|
384
|
+
def self.basic_cancel(id, consumer_tag, no_wait: false)
|
387
385
|
frame_size = 2 + 2 + 1 + consumer_tag.bytesize + 1
|
388
386
|
[
|
389
387
|
1, # type: method
|
@@ -397,7 +395,7 @@ module AMQP
|
|
397
395
|
].pack("C S> L> S> S> Ca* C C")
|
398
396
|
end
|
399
397
|
|
400
|
-
def basic_cancel_ok(id, consumer_tag)
|
398
|
+
def self.basic_cancel_ok(id, consumer_tag)
|
401
399
|
frame_size = 2 + 2 + 1 + consumer_tag.bytesize + 1
|
402
400
|
[
|
403
401
|
1, # type: method
|
@@ -410,7 +408,7 @@ module AMQP
|
|
410
408
|
].pack("C S> L> S> S> Ca* C")
|
411
409
|
end
|
412
410
|
|
413
|
-
def basic_ack(id, delivery_tag, multiple)
|
411
|
+
def self.basic_ack(id, delivery_tag, multiple)
|
414
412
|
frame_size = 2 + 2 + 8 + 1
|
415
413
|
[
|
416
414
|
1, # type: method
|
@@ -424,7 +422,7 @@ module AMQP
|
|
424
422
|
].pack("C S> L> S> S> Q> C C")
|
425
423
|
end
|
426
424
|
|
427
|
-
def basic_nack(id, delivery_tag, multiple, requeue)
|
425
|
+
def self.basic_nack(id, delivery_tag, multiple, requeue)
|
428
426
|
bits = 0
|
429
427
|
bits |= (1 << 0) if multiple
|
430
428
|
bits |= (1 << 1) if requeue
|
@@ -441,7 +439,7 @@ module AMQP
|
|
441
439
|
].pack("C S> L> S> S> Q> C C")
|
442
440
|
end
|
443
441
|
|
444
|
-
def basic_reject(id, delivery_tag, requeue)
|
442
|
+
def self.basic_reject(id, delivery_tag, requeue)
|
445
443
|
frame_size = 2 + 2 + 8 + 1
|
446
444
|
[
|
447
445
|
1, # type: method
|
@@ -455,7 +453,7 @@ module AMQP
|
|
455
453
|
].pack("C S> L> S> S> Q> C C")
|
456
454
|
end
|
457
455
|
|
458
|
-
def basic_qos(id, prefetch_size, prefetch_count, global)
|
456
|
+
def self.basic_qos(id, prefetch_size, prefetch_count, global)
|
459
457
|
frame_size = 2 + 2 + 4 + 2 + 1
|
460
458
|
[
|
461
459
|
1, # type: method
|
@@ -470,7 +468,7 @@ module AMQP
|
|
470
468
|
].pack("C S> L> S> S> L> S> C C")
|
471
469
|
end
|
472
470
|
|
473
|
-
def basic_recover(id, requeue)
|
471
|
+
def self.basic_recover(id, requeue)
|
474
472
|
frame_size = 2 + 2 + 1
|
475
473
|
[
|
476
474
|
1, # type: method
|
@@ -483,7 +481,7 @@ module AMQP
|
|
483
481
|
].pack("C S> L> S> S> C C")
|
484
482
|
end
|
485
483
|
|
486
|
-
def confirm_select(id, no_wait)
|
484
|
+
def self.confirm_select(id, no_wait)
|
487
485
|
[
|
488
486
|
1, # type: method
|
489
487
|
id, # channel id
|
@@ -495,7 +493,7 @@ module AMQP
|
|
495
493
|
].pack("C S> L> S> S> C C")
|
496
494
|
end
|
497
495
|
|
498
|
-
def tx_select(id)
|
496
|
+
def self.tx_select(id)
|
499
497
|
frame_size = 2 + 2
|
500
498
|
[
|
501
499
|
1, # type: method
|
@@ -507,7 +505,7 @@ module AMQP
|
|
507
505
|
].pack("C S> L> S> S> C")
|
508
506
|
end
|
509
507
|
|
510
|
-
def tx_commit(id)
|
508
|
+
def self.tx_commit(id)
|
511
509
|
frame_size = 2 + 2
|
512
510
|
[
|
513
511
|
1, # type: method
|
@@ -519,7 +517,7 @@ module AMQP
|
|
519
517
|
].pack("C S> L> S> S> C")
|
520
518
|
end
|
521
519
|
|
522
|
-
def tx_rollback(id)
|
520
|
+
def self.tx_rollback(id)
|
523
521
|
frame_size = 2 + 2
|
524
522
|
[
|
525
523
|
1, # type: method
|
data/lib/amqp/client/message.rb
CHANGED
@@ -3,52 +3,109 @@
|
|
3
3
|
module AMQP
|
4
4
|
class Client
|
5
5
|
# A message delivered from the broker
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# @return [String] The message body
|
18
|
-
# @!attribute redelivered
|
19
|
-
# @return [Boolean] True if the message have been delivered before
|
20
|
-
# @!attribute consumer_tag
|
21
|
-
# @return [String] The tag of the consumer the message was deliviered to
|
22
|
-
# @return [nil] Nil if the message was polled and not deliviered to a consumer
|
23
|
-
Message =
|
24
|
-
Struct.new(:channel, :delivery_tag, :exchange_name, :routing_key, :properties, :body, :redelivered, :consumer_tag) do
|
25
|
-
# Acknowledge the message
|
26
|
-
# @return [nil]
|
27
|
-
def ack
|
28
|
-
channel.basic_ack(delivery_tag)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Reject the message
|
32
|
-
# @param requeue [Boolean] If true the message will be put back into the queue again, ready to be redelivered
|
33
|
-
# @return [nil]
|
34
|
-
def reject(requeue: false)
|
35
|
-
channel.basic_reject(delivery_tag, requeue: requeue)
|
36
|
-
end
|
6
|
+
class Message
|
7
|
+
# @api private
|
8
|
+
def initialize(channel, consumer_tag, delivery_tag, exchange, routing_key, redelivered)
|
9
|
+
@channel = channel
|
10
|
+
@consumer_tag = consumer_tag
|
11
|
+
@delivery_tag = delivery_tag
|
12
|
+
@exchange = exchange
|
13
|
+
@routing_key = routing_key
|
14
|
+
@redelivered = redelivered
|
15
|
+
@properties = nil
|
16
|
+
@body = ""
|
37
17
|
end
|
38
18
|
|
19
|
+
# The channel the message was deliviered to
|
20
|
+
# @return [Connection::Channel]
|
21
|
+
attr_reader :channel
|
22
|
+
|
23
|
+
# The tag of the consumer the message was deliviered to
|
24
|
+
# @return [String]
|
25
|
+
# @return [nil] If the message was polled and not deliviered to a consumer
|
26
|
+
attr_reader :consumer_tag
|
27
|
+
|
28
|
+
# The delivery tag of the message, used for acknowledge or reject the message
|
29
|
+
# @return [Integer]
|
30
|
+
attr_reader :delivery_tag
|
31
|
+
|
32
|
+
# Name of the exchange the message was published to
|
33
|
+
# @return [String]
|
34
|
+
attr_reader :exchange
|
35
|
+
|
36
|
+
# The routing key the message was published with
|
37
|
+
# @return [String]
|
38
|
+
attr_reader :routing_key
|
39
|
+
|
40
|
+
# True if the message have been delivered before
|
41
|
+
# @return [Boolean]
|
42
|
+
attr_reader :redelivered
|
43
|
+
|
44
|
+
# Message properties
|
45
|
+
# @return [Properties]
|
46
|
+
attr_accessor :properties
|
47
|
+
|
48
|
+
# The message body
|
49
|
+
# @return [String]
|
50
|
+
attr_accessor :body
|
51
|
+
|
52
|
+
# Acknowledge the message
|
53
|
+
# @return [nil]
|
54
|
+
def ack
|
55
|
+
@channel.basic_ack(@delivery_tag)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Reject the message
|
59
|
+
# @param requeue [Boolean] If true the message will be put back into the queue again, ready to be redelivered
|
60
|
+
# @return [nil]
|
61
|
+
def reject(requeue: false)
|
62
|
+
@channel.basic_reject(@delivery_tag, requeue: requeue)
|
63
|
+
end
|
64
|
+
|
65
|
+
# @see #exchange
|
66
|
+
# @deprecated
|
67
|
+
# @!attribute [r] exchange_name
|
68
|
+
# @return [String]
|
69
|
+
def exchange_name
|
70
|
+
@exchange
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
39
74
|
# A published message returned by the broker due to some error
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
75
|
+
class ReturnMessage
|
76
|
+
# @api private
|
77
|
+
def initialize(reply_code, reply_text, exchange, routing_key)
|
78
|
+
@reply_code = reply_code
|
79
|
+
@reply_text = reply_text
|
80
|
+
@exchange = exchange
|
81
|
+
@routing_key = routing_key
|
82
|
+
@properties = nil
|
83
|
+
@body = ""
|
84
|
+
end
|
85
|
+
|
86
|
+
# Error code
|
87
|
+
# @return [Integer]
|
88
|
+
attr_reader :reply_code
|
89
|
+
|
90
|
+
# Description on why the message was returned
|
91
|
+
# @return [String]
|
92
|
+
attr_reader :reply_text
|
93
|
+
|
94
|
+
# Name of the exchange the message was published to
|
95
|
+
# @return [String]
|
96
|
+
attr_reader :exchange
|
97
|
+
|
98
|
+
# The routing key the message was published with
|
99
|
+
# @return [String]
|
100
|
+
attr_reader :routing_key
|
101
|
+
|
102
|
+
# Message properties
|
103
|
+
# @return [Properties]
|
104
|
+
attr_accessor :properties
|
105
|
+
|
106
|
+
# The message body
|
107
|
+
# @return [String]
|
108
|
+
attr_accessor :body
|
109
|
+
end
|
53
110
|
end
|
54
111
|
end
|