amqp-client 1.0.2 → 1.1.0
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 +1 -2
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile +4 -0
- data/README.md +56 -27
- data/Rakefile +3 -1
- data/amqp-client.gemspec +1 -1
- data/lib/amqp/client/channel.rb +11 -10
- data/lib/amqp/client/connection.rb +61 -42
- data/lib/amqp/client/frames.rb +33 -35
- data/lib/amqp/client/message.rb +101 -44
- data/lib/amqp/client/properties.rb +83 -53
- data/lib/amqp/client/table.rb +7 -9
- data/lib/amqp/client/version.rb +1 -1
- data/lib/amqp/client.rb +4 -4
- data/sig/amqp-client.rbs +264 -0
- metadata +4 -3
data/lib/amqp/client/frames.rb
CHANGED
@@ -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,7 +331,7 @@ 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)
|
334
|
+
def self.header(id, body_size, properties)
|
337
335
|
props = Properties.new(**properties).encode
|
338
336
|
frame_size = 2 + 2 + 8 + props.bytesize
|
339
337
|
[
|
@@ -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
|
@@ -5,35 +5,65 @@ require_relative "./table"
|
|
5
5
|
module AMQP
|
6
6
|
class Client
|
7
7
|
# Encode/decode AMQP Properties
|
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
|
-
|
8
|
+
class Properties
|
9
|
+
def initialize(content_type: nil, content_encoding: nil, headers: nil, delivery_mode: nil, priority: nil, correlation_id: nil,
|
10
|
+
reply_to: nil, expiration: nil, message_id: nil, timestamp: nil, type: nil, user_id: nil, app_id: nil)
|
11
|
+
@content_type = content_type
|
12
|
+
@content_encoding = content_encoding
|
13
|
+
@headers = headers
|
14
|
+
@delivery_mode = delivery_mode
|
15
|
+
@priority = priority
|
16
|
+
@correlation_id = correlation_id
|
17
|
+
@reply_to = reply_to
|
18
|
+
@expiration = expiration
|
19
|
+
@message_id = message_id
|
20
|
+
@timestamp = timestamp
|
21
|
+
@type = type
|
22
|
+
@user_id = user_id
|
23
|
+
@app_id = app_id
|
24
|
+
end
|
25
|
+
|
26
|
+
# Content type of the message body
|
27
|
+
# @return [String, nil]
|
28
|
+
attr_accessor :content_type
|
29
|
+
# Content encoding of the body
|
30
|
+
# @return [String, nil]
|
31
|
+
attr_accessor :content_encoding
|
32
|
+
# Custom headers
|
33
|
+
# @return [Hash<String, Object>, nil]
|
34
|
+
attr_accessor :headers
|
35
|
+
# 2 for persisted message, transient messages for all other values
|
36
|
+
# @return [Integer, nil]
|
37
|
+
attr_accessor :delivery_mode
|
38
|
+
# A priority of the message (between 0 and 255)
|
39
|
+
# @return [Integer, nil]
|
40
|
+
attr_accessor :priority
|
41
|
+
# A correlation id, most often used used for RPC communication
|
42
|
+
# @return [Integer, nil]
|
43
|
+
attr_accessor :correlation_id
|
44
|
+
# Queue to reply RPC responses to
|
45
|
+
# @return [String, nil]
|
46
|
+
attr_accessor :reply_to
|
47
|
+
# Number of seconds the message will stay in the queue
|
48
|
+
# @return [Integer]
|
49
|
+
# @return [String]
|
50
|
+
# @return [nil]
|
51
|
+
attr_accessor :expiration
|
52
|
+
# @return [String, nil]
|
53
|
+
attr_accessor :message_id
|
54
|
+
# User-definable, but often used for the time the message was originally generated
|
55
|
+
# @return [Date, nil]
|
56
|
+
attr_accessor :timestamp
|
57
|
+
# User-definable, but can can indicate what kind of message this is
|
58
|
+
# @return [String, nil]
|
59
|
+
attr_accessor :type
|
60
|
+
# User-definable, but can be used to verify that this is the user that published the message
|
61
|
+
# @return [String, nil]
|
62
|
+
attr_accessor :user_id
|
63
|
+
# User-definable, but often indicates which app that generated the message
|
64
|
+
# @return [String, nil]
|
65
|
+
attr_accessor :app_id
|
66
|
+
|
37
67
|
# Encode properties into a byte array
|
38
68
|
# @return [String] byte array
|
39
69
|
def encode
|
@@ -155,81 +185,81 @@ module AMQP
|
|
155
185
|
# Decode a byte array
|
156
186
|
# @return [Properties]
|
157
187
|
def self.decode(bytes)
|
158
|
-
|
188
|
+
p = new
|
159
189
|
flags = bytes.unpack1("S>")
|
160
190
|
pos = 2
|
161
191
|
if (flags & 0x8000).positive?
|
162
|
-
len = bytes
|
192
|
+
len = bytes.getbyte(pos)
|
163
193
|
pos += 1
|
164
|
-
|
194
|
+
p.content_type = bytes.byteslice(pos, len).force_encoding("utf-8")
|
165
195
|
pos += len
|
166
196
|
end
|
167
197
|
if (flags & 0x4000).positive?
|
168
|
-
len = bytes
|
198
|
+
len = bytes.getbyte(pos)
|
169
199
|
pos += 1
|
170
|
-
|
200
|
+
p.content_encoding = bytes.byteslice(pos, len).force_encoding("utf-8")
|
171
201
|
pos += len
|
172
202
|
end
|
173
203
|
if (flags & 0x2000).positive?
|
174
204
|
len = bytes.byteslice(pos, 4).unpack1("L>")
|
175
205
|
pos += 4
|
176
|
-
|
206
|
+
p.headers = Table.decode(bytes.byteslice(pos, len))
|
177
207
|
pos += len
|
178
208
|
end
|
179
209
|
if (flags & 0x1000).positive?
|
180
|
-
|
210
|
+
p.delivery_mode = bytes.getbyte(pos)
|
181
211
|
pos += 1
|
182
212
|
end
|
183
213
|
if (flags & 0x0800).positive?
|
184
|
-
|
214
|
+
p.priority = bytes.getbyte(pos)
|
185
215
|
pos += 1
|
186
216
|
end
|
187
217
|
if (flags & 0x0400).positive?
|
188
|
-
len = bytes
|
218
|
+
len = bytes.getbyte(pos)
|
189
219
|
pos += 1
|
190
|
-
|
220
|
+
p.correlation_id = bytes.byteslice(pos, len).force_encoding("utf-8")
|
191
221
|
pos += len
|
192
222
|
end
|
193
223
|
if (flags & 0x0200).positive?
|
194
|
-
len = bytes
|
224
|
+
len = bytes.getbyte(pos)
|
195
225
|
pos += 1
|
196
|
-
|
226
|
+
p.reply_to = bytes.byteslice(pos, len).force_encoding("utf-8")
|
197
227
|
pos += len
|
198
228
|
end
|
199
229
|
if (flags & 0x0100).positive?
|
200
|
-
len = bytes
|
230
|
+
len = bytes.getbyte(pos)
|
201
231
|
pos += 1
|
202
|
-
|
232
|
+
p.expiration = bytes.byteslice(pos, len).force_encoding("utf-8")
|
203
233
|
pos += len
|
204
234
|
end
|
205
235
|
if (flags & 0x0080).positive?
|
206
|
-
len = bytes
|
236
|
+
len = bytes.getbyte(pos)
|
207
237
|
pos += 1
|
208
|
-
|
238
|
+
p.message_id = bytes.byteslice(pos, len).force_encoding("utf-8")
|
209
239
|
pos += len
|
210
240
|
end
|
211
241
|
if (flags & 0x0040).positive?
|
212
|
-
|
242
|
+
p.timestamp = Time.at(bytes.byteslice(pos, 8).unpack1("Q>"))
|
213
243
|
pos += 8
|
214
244
|
end
|
215
245
|
if (flags & 0x0020).positive?
|
216
|
-
len = bytes
|
246
|
+
len = bytes.getbyte(pos)
|
217
247
|
pos += 1
|
218
|
-
|
248
|
+
p.type = bytes.byteslice(pos, len).force_encoding("utf-8")
|
219
249
|
pos += len
|
220
250
|
end
|
221
251
|
if (flags & 0x0010).positive?
|
222
|
-
len = bytes
|
252
|
+
len = bytes.getbyte(pos)
|
223
253
|
pos += 1
|
224
|
-
|
254
|
+
p.user_id = bytes.byteslice(pos, len).force_encoding("utf-8")
|
225
255
|
pos += len
|
226
256
|
end
|
227
257
|
if (flags & 0x0008).positive?
|
228
|
-
len = bytes
|
258
|
+
len = bytes.getbyte(pos)
|
229
259
|
pos += 1
|
230
|
-
|
260
|
+
p.app_id = bytes.byteslice(pos, len).force_encoding("utf-8")
|
231
261
|
end
|
232
|
-
|
262
|
+
p
|
233
263
|
end
|
234
264
|
end
|
235
265
|
end
|