-
Notifications
You must be signed in to change notification settings - Fork 194
/
channel.py
2078 lines (1533 loc) · 70.1 KB
/
channel.py
1
2
3
4
5
6
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
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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
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
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
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""AMQP Channels"""
# Copyright (C) 2007-2008 Barry Pederson <bp@barryp.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
from __future__ import absolute_import
import logging
import socket
from collections import defaultdict
from warnings import warn
from vine import ensure_promise
from . import spec
from .abstract_channel import AbstractChannel
from .exceptions import ChannelError, ConsumerCancelled, error_for_code
from .five import Queue
from .protocol import queue_declare_ok_t
__all__ = ['Channel']
AMQP_LOGGER = logging.getLogger('amqp')
EXCHANGE_AUTODELETE_DEPRECATED = """\
The auto_delete flag for exchanges has been deprecated and will be removed
from py-amqp v1.5.0.\
"""
REJECTED_MESSAGE_WITHOUT_CALLBACK = """\
Rejecting message with delivery tag %r for reason of having no callbacks.
consumer_tag=%r exchange=%r routing_key=%r.\
"""
class VDeprecationWarning(DeprecationWarning):
pass
class Channel(AbstractChannel):
"""Work with channels
The channel class provides methods for a client to establish a
virtual connection - a channel - to a server and for both peers to
operate the virtual connection thereafter.
GRAMMAR::
channel = open-channel *use-channel close-channel
open-channel = C:OPEN S:OPEN-OK
use-channel = C:FLOW S:FLOW-OK
/ S:FLOW C:FLOW-OK
/ functional-class
close-channel = C:CLOSE S:CLOSE-OK
/ S:CLOSE C:CLOSE-OK
"""
_METHODS = set([
spec.method(spec.Channel.Close, 'BsBB'),
spec.method(spec.Channel.CloseOk),
spec.method(spec.Channel.Flow, 'b'),
spec.method(spec.Channel.FlowOk, 'b'),
spec.method(spec.Channel.OpenOk),
spec.method(spec.Exchange.DeclareOk),
spec.method(spec.Exchange.DeleteOk),
spec.method(spec.Exchange.BindOk),
spec.method(spec.Exchange.UnbindOk),
spec.method(spec.Queue.BindOk),
spec.method(spec.Queue.UnbindOk),
spec.method(spec.Queue.DeclareOk, 'sll'),
spec.method(spec.Queue.DeleteOk, 'l'),
spec.method(spec.Queue.PurgeOk, 'l'),
spec.method(spec.Basic.Cancel, 's'),
spec.method(spec.Basic.CancelOk, 's'),
spec.method(spec.Basic.ConsumeOk, 's'),
spec.method(spec.Basic.Deliver, 'sLbss', content=True),
spec.method(spec.Basic.GetEmpty, 's'),
spec.method(spec.Basic.GetOk, 'Lbssl', content=True),
spec.method(spec.Basic.QosOk),
spec.method(spec.Basic.RecoverOk),
spec.method(spec.Basic.Return, 'Bsss', content=True),
spec.method(spec.Tx.CommitOk),
spec.method(spec.Tx.RollbackOk),
spec.method(spec.Tx.SelectOk),
spec.method(spec.Confirm.SelectOk),
spec.method(spec.Basic.Ack, 'Lb'),
])
_METHODS = {m.method_sig: m for m in _METHODS}
def __init__(self, connection,
channel_id=None, auto_decode=True, on_open=None):
"""Create a channel bound to a connection and using the specified
numeric channel_id, and open on the server.
The 'auto_decode' parameter (defaults to True), indicates
whether the library should attempt to decode the body
of Messages to a Unicode string if there's a 'content_encoding'
property for the message. If there's no 'content_encoding'
property, or the decode raises an Exception, the message body
is left as plain bytes.
"""
if channel_id:
connection._claim_channel_id(channel_id)
else:
channel_id = connection._get_free_channel_id()
AMQP_LOGGER.debug('using channel_id: %s', channel_id)
super(Channel, self).__init__(connection, channel_id)
self.is_open = False
self.active = True # Flow control
self.returned_messages = Queue()
self.callbacks = {}
self.cancel_callbacks = {}
self.auto_decode = auto_decode
self.events = defaultdict(set)
self.no_ack_consumers = set()
self.on_open = ensure_promise(on_open)
# set first time basic_publish_confirm is called
# and publisher confirms are enabled for this channel.
self._confirm_selected = False
if self.connection.confirm_publish:
self.basic_publish = self.basic_publish_confirm
def then(self, on_success, on_error=None):
return self.on_open.then(on_success, on_error)
def _setup_listeners(self):
self._callbacks.update({
spec.Channel.Close: self._on_close,
spec.Channel.CloseOk: self._on_close_ok,
spec.Channel.Flow: self._on_flow,
spec.Channel.OpenOk: self._on_open_ok,
spec.Basic.Cancel: self._on_basic_cancel,
spec.Basic.CancelOk: self._on_basic_cancel_ok,
spec.Basic.Deliver: self._on_basic_deliver,
spec.Basic.Return: self._on_basic_return,
spec.Basic.Ack: self._on_basic_ack,
})
def collect(self):
"""Tear down this object, after we've agreed to close
with the server."""
AMQP_LOGGER.debug('Closed channel #%s', self.channel_id)
self.is_open = False
channel_id, self.channel_id = self.channel_id, None
connection, self.connection = self.connection, None
if connection:
connection.channels.pop(channel_id, None)
connection._avail_channel_ids.append(channel_id)
self.callbacks.clear()
self.cancel_callbacks.clear()
self.events.clear()
self.no_ack_consumers.clear()
def _do_revive(self):
self.is_open = False
self.open()
def close(self, reply_code=0, reply_text='', method_sig=(0, 0),
argsig='BsBB'):
"""Request a channel close
This method indicates that the sender wants to close the
channel. This may be due to internal conditions (e.g. a forced
shut-down) or due to an error handling a specific method, i.e.
an exception. When a close is due to an exception, the sender
provides the class and method id of the method which caused
the exception.
RULE:
After sending this method any received method except
Channel.Close-OK MUST be discarded.
RULE:
The peer sending this method MAY use a counter or timeout
to detect failure of the other peer to respond correctly
with Channel.Close-OK..
PARAMETERS:
reply_code: short
The reply code. The AMQ reply codes are defined in AMQ
RFC 011.
reply_text: shortstr
The localised reply text. This text can be logged as an
aid to resolving issues.
class_id: short
failing method class
When the close is provoked by a method exception, this
is the class of the method.
method_id: short
failing method ID
When the close is provoked by a method exception, this
is the ID of the method.
"""
try:
is_closed = (
not self.is_open or
self.connection is None or
self.connection.channels is None
)
if is_closed:
return
return self.send_method(
spec.Channel.Close, argsig,
(reply_code, reply_text, method_sig[0], method_sig[1]),
wait=spec.Channel.CloseOk,
)
finally:
self.connection = None
def _on_close(self, reply_code, reply_text, class_id, method_id):
"""Request a channel close
This method indicates that the sender wants to close the
channel. This may be due to internal conditions (e.g. a forced
shut-down) or due to an error handling a specific method, i.e.
an exception. When a close is due to an exception, the sender
provides the class and method id of the method which caused
the exception.
RULE:
After sending this method any received method except
Channel.Close-OK MUST be discarded.
RULE:
The peer sending this method MAY use a counter or timeout
to detect failure of the other peer to respond correctly
with Channel.Close-OK..
PARAMETERS:
reply_code: short
The reply code. The AMQ reply codes are defined in AMQ
RFC 011.
reply_text: shortstr
The localised reply text. This text can be logged as an
aid to resolving issues.
class_id: short
failing method class
When the close is provoked by a method exception, this
is the class of the method.
method_id: short
failing method ID
When the close is provoked by a method exception, this
is the ID of the method.
"""
self.send_method(spec.Channel.CloseOk)
self._do_revive()
raise error_for_code(
reply_code, reply_text, (class_id, method_id), ChannelError,
)
def _on_close_ok(self):
"""Confirm a channel close
This method confirms a Channel.Close method and tells the
recipient that it is safe to release resources for the channel
and close the socket.
RULE:
A peer that detects a socket closure without having
received a Channel.Close-Ok handshake method SHOULD log
the error.
"""
self.collect()
def flow(self, active):
"""Enable/disable flow from peer
This method asks the peer to pause or restart the flow of
content data. This is a simple flow-control mechanism that a
peer can use to avoid oveflowing its queues or otherwise
finding itself receiving more messages than it can process.
Note that this method is not intended for window control. The
peer that receives a request to stop sending content should
finish sending the current content, if any, and then wait
until it receives a Flow restart method.
RULE:
When a new channel is opened, it is active. Some
applications assume that channels are inactive until
started. To emulate this behaviour a client MAY open the
channel, then pause it.
RULE:
When sending content data in multiple frames, a peer
SHOULD monitor the channel for incoming methods and
respond to a Channel.Flow as rapidly as possible.
RULE:
A peer MAY use the Channel.Flow method to throttle
incoming content data for internal reasons, for example,
when exchangeing data over a slower connection.
RULE:
The peer that requests a Channel.Flow method MAY
disconnect and/or ban a peer that does not respect the
request.
PARAMETERS:
active: boolean
start/stop content frames
If True, the peer starts sending content frames. If
False, the peer stops sending content frames.
"""
return self.send_method(
spec.Channel.Flow, 'b', (active,), wait=spec.Channel.FlowOk,
)
def _on_flow(self, active):
"""Enable/disable flow from peer
This method asks the peer to pause or restart the flow of
content data. This is a simple flow-control mechanism that a
peer can use to avoid oveflowing its queues or otherwise
finding itself receiving more messages than it can process.
Note that this method is not intended for window control. The
peer that receives a request to stop sending content should
finish sending the current content, if any, and then wait
until it receives a Flow restart method.
RULE:
When a new channel is opened, it is active. Some
applications assume that channels are inactive until
started. To emulate this behaviour a client MAY open the
channel, then pause it.
RULE:
When sending content data in multiple frames, a peer
SHOULD monitor the channel for incoming methods and
respond to a Channel.Flow as rapidly as possible.
RULE:
A peer MAY use the Channel.Flow method to throttle
incoming content data for internal reasons, for example,
when exchangeing data over a slower connection.
RULE:
The peer that requests a Channel.Flow method MAY
disconnect and/or ban a peer that does not respect the
request.
PARAMETERS:
active: boolean
start/stop content frames
If True, the peer starts sending content frames. If
False, the peer stops sending content frames.
"""
self.active = active
self._x_flow_ok(self.active)
def _x_flow_ok(self, active):
"""Confirm a flow method
Confirms to the peer that a flow command was received and
processed.
PARAMETERS:
active: boolean
current flow setting
Confirms the setting of the processed flow method:
True means the peer will start sending or continue
to send content frames; False means it will not.
"""
return self.send_method(spec.Channel.FlowOk, 'b', (active,))
def open(self):
"""Open a channel for use
This method opens a virtual connection (a channel).
RULE:
This method MUST NOT be called when the channel is already
open.
PARAMETERS:
out_of_band: shortstr (DEPRECATED)
out-of-band settings
Configures out-of-band transfers on this channel. The
syntax and meaning of this field will be formally
defined at a later date.
"""
if self.is_open:
return
return self.send_method(
spec.Channel.Open, 's', ('',), wait=spec.Channel.OpenOk,
)
def _on_open_ok(self):
"""Signal that the channel is ready
This method signals to the client that the channel is ready
for use.
"""
self.is_open = True
self.on_open(self)
AMQP_LOGGER.debug('Channel open')
#############
#
# Exchange
#
#
# work with exchanges
#
# Exchanges match and distribute messages across queues.
# Exchanges can be configured in the server or created at runtime.
#
# GRAMMAR::
#
# exchange = C:DECLARE S:DECLARE-OK
# / C:DELETE S:DELETE-OK
#
# RULE:
#
# The server MUST implement the direct and fanout exchange
# types, and predeclare the corresponding exchanges named
# amq.direct and amq.fanout in each virtual host. The server
# MUST also predeclare a direct exchange to act as the default
# exchange for content Publish methods and for default queue
# bindings.
#
# RULE:
#
# The server SHOULD implement the topic exchange type, and
# predeclare the corresponding exchange named amq.topic in
# each virtual host.
#
# RULE:
#
# The server MAY implement the system exchange type, and
# predeclare the corresponding exchanges named amq.system in
# each virtual host. If the client attempts to bind a queue to
# the system exchange, the server MUST raise a connection
# exception with reply code 507 (not allowed).
#
def exchange_declare(self, exchange, type, passive=False, durable=False,
auto_delete=True, nowait=False, arguments=None,
argsig='BssbbbbbF'):
"""Declare exchange, create if needed
This method creates an exchange if it does not already exist,
and if the exchange exists, verifies that it is of the correct
and expected class.
RULE:
The server SHOULD support a minimum of 16 exchanges per
virtual host and ideally, impose no limit except as
defined by available resources.
PARAMETERS:
exchange: shortstr
RULE:
Exchange names starting with "amq." are reserved
for predeclared and standardised exchanges. If
the client attempts to create an exchange starting
with "amq.", the server MUST raise a channel
exception with reply code 403 (access refused).
type: shortstr
exchange type
Each exchange belongs to one of a set of exchange
types implemented by the server. The exchange types
define the functionality of the exchange - i.e. how
messages are routed through it. It is not valid or
meaningful to attempt to change the type of an
existing exchange.
RULE:
If the exchange already exists with a different
type, the server MUST raise a connection exception
with a reply code 507 (not allowed).
RULE:
If the server does not support the requested
exchange type it MUST raise a connection exception
with a reply code 503 (command invalid).
passive: boolean
do not create exchange
If set, the server will not create the exchange. The
client can use this to check whether an exchange
exists without modifying the server state.
RULE:
If set, and the exchange does not already exist,
the server MUST raise a channel exception with
reply code 404 (not found).
durable: boolean
request a durable exchange
If set when creating a new exchange, the exchange will
be marked as durable. Durable exchanges remain active
when a server restarts. Non-durable exchanges
(transient exchanges) are purged if/when a server
restarts.
RULE:
The server MUST support both durable and transient
exchanges.
RULE:
The server MUST ignore the durable field if the
exchange already exists.
auto_delete: boolean
auto-delete when unused
If set, the exchange is deleted when all queues have
finished using it.
RULE:
The server SHOULD allow for a reasonable delay
between the point when it determines that an
exchange is not being used (or no longer used),
and the point when it deletes the exchange. At
the least it must allow a client to create an
exchange and then bind a queue to it, with a small
but non-zero delay between these two actions.
RULE:
The server MUST ignore the auto-delete field if
the exchange already exists.
nowait: boolean
do not send a reply method
If set, the server will not respond to the method. The
client should not wait for a reply method. If the
server could not complete the method it will raise a
channel or connection exception.
arguments: table
arguments for declaration
A set of arguments for the declaration. The syntax and
semantics of these arguments depends on the server
implementation. This field is ignored if passive is
True.
"""
if auto_delete:
warn(VDeprecationWarning(EXCHANGE_AUTODELETE_DEPRECATED))
self.send_method(
spec.Exchange.Declare, argsig,
(0, exchange, type, passive, durable, auto_delete,
False, nowait, arguments),
wait=None if nowait else spec.Exchange.DeclareOk,
)
def exchange_delete(self, exchange, if_unused=False, nowait=False,
argsig='Bsbb'):
"""Delete an exchange
This method deletes an exchange. When an exchange is deleted
all queue bindings on the exchange are cancelled.
PARAMETERS:
exchange: shortstr
RULE:
The exchange MUST exist. Attempting to delete a
non-existing exchange causes a channel exception.
if_unused: boolean
delete only if unused
If set, the server will only delete the exchange if it
has no queue bindings. If the exchange has queue
bindings the server does not delete it but raises a
channel exception instead.
RULE:
If set, the server SHOULD delete the exchange but
only if it has no queue bindings.
RULE:
If set, the server SHOULD raise a channel
exception if the exchange is in use.
nowait: boolean
do not send a reply method
If set, the server will not respond to the method. The
client should not wait for a reply method. If the
server could not complete the method it will raise a
channel or connection exception.
"""
return self.send_method(
spec.Exchange.Delete, argsig, (0, exchange, if_unused, nowait),
wait=None if nowait else spec.Exchange.DeleteOk,
)
def exchange_bind(self, destination, source='', routing_key='',
nowait=False, arguments=None, argsig='BsssbF'):
"""This method binds an exchange to an exchange.
RULE:
A server MUST allow and ignore duplicate bindings - that
is, two or more bind methods for a specific exchanges,
with identical arguments - without treating these as an
error.
RULE:
A server MUST allow cycles of exchange bindings to be
created including allowing an exchange to be bound to
itself.
RULE:
A server MUST not deliver the same message more than once
to a destination exchange, even if the topology of
exchanges and bindings results in multiple (even infinite)
routes to that exchange.
PARAMETERS:
reserved-1: short
destination: shortstr
Specifies the name of the destination exchange to
bind.
RULE:
A client MUST NOT be allowed to bind a non-
existent destination exchange.
RULE:
The server MUST accept a blank exchange name to
mean the default exchange.
source: shortstr
Specifies the name of the source exchange to bind.
RULE:
A client MUST NOT be allowed to bind a non-
existent source exchange.
RULE:
The server MUST accept a blank exchange name to
mean the default exchange.
routing-key: shortstr
Specifies the routing key for the binding. The routing
key is used for routing messages depending on the
exchange configuration. Not all exchanges use a
routing key - refer to the specific exchange
documentation.
no-wait: bit
arguments: table
A set of arguments for the binding. The syntax and
semantics of these arguments depends on the exchange
class.
"""
return self.send_method(
spec.Exchange.Bind, argsig,
(0, destination, source, routing_key, nowait, arguments),
wait=None if nowait else spec.Exchange.BindOk,
)
def exchange_unbind(self, destination, source='', routing_key='',
nowait=False, arguments=None, argsig='BsssbF'):
"""This method unbinds an exchange from an exchange.
RULE:
If a unbind fails, the server MUST raise a connection
exception.
PARAMETERS:
reserved-1: short
destination: shortstr
Specifies the name of the destination exchange to
unbind.
RULE:
The client MUST NOT attempt to unbind an exchange
that does not exist from an exchange.
RULE:
The server MUST accept a blank exchange name to
mean the default exchange.
source: shortstr
Specifies the name of the source exchange to unbind.
RULE:
The client MUST NOT attempt to unbind an exchange
from an exchange that does not exist.
RULE:
The server MUST accept a blank exchange name to
mean the default exchange.
routing-key: shortstr
Specifies the routing key of the binding to unbind.
no-wait: bit
arguments: table
Specifies the arguments of the binding to unbind.
"""
return self.send_method(
spec.Exchange.Unbind, argsig,
(0, destination, source, routing_key, nowait, arguments),
wait=None if nowait else spec.Exchange.UnbindOk,
)
#############
#
# Queue
#
#
# work with queues
#
# Queues store and forward messages. Queues can be configured in
# the server or created at runtime. Queues must be attached to at
# least one exchange in order to receive messages from publishers.
#
# GRAMMAR::
#
# queue = C:DECLARE S:DECLARE-OK
# / C:BIND S:BIND-OK
# / C:PURGE S:PURGE-OK
# / C:DELETE S:DELETE-OK
#
# RULE:
#
# A server MUST allow any content class to be sent to any
# queue, in any mix, and queue and delivery these content
# classes independently. Note that all methods that fetch
# content off queues are specific to a given content class.
#
def queue_bind(self, queue, exchange='', routing_key='',
nowait=False, arguments=None, argsig='BsssbF'):
"""Bind queue to an exchange
This method binds a queue to an exchange. Until a queue is
bound it will not receive any messages. In a classic
messaging model, store-and-forward queues are bound to a dest
exchange and subscription queues are bound to a dest_wild
exchange.
RULE:
A server MUST allow ignore duplicate bindings - that is,
two or more bind methods for a specific queue, with
identical arguments - without treating these as an error.
RULE:
If a bind fails, the server MUST raise a connection
exception.
RULE:
The server MUST NOT allow a durable queue to bind to a
transient exchange. If the client attempts this the server
MUST raise a channel exception.
RULE:
Bindings for durable queues are automatically durable and
the server SHOULD restore such bindings after a server
restart.
RULE:
The server SHOULD support at least 4 bindings per queue,
and ideally, impose no limit except as defined by
available resources.
PARAMETERS:
queue: shortstr
Specifies the name of the queue to bind. If the queue
name is empty, refers to the current queue for the
channel, which is the last declared queue.
RULE:
If the client did not previously declare a queue,
and the queue name in this method is empty, the
server MUST raise a connection exception with
reply code 530 (not allowed).
RULE:
If the queue does not exist the server MUST raise
a channel exception with reply code 404 (not
found).
exchange: shortstr
The name of the exchange to bind to.
RULE:
If the exchange does not exist the server MUST
raise a channel exception with reply code 404 (not
found).
routing_key: shortstr
message routing key
Specifies the routing key for the binding. The
routing key is used for routing messages depending on
the exchange configuration. Not all exchanges use a
routing key - refer to the specific exchange
documentation. If the routing key is empty and the
queue name is empty, the routing key will be the
current queue for the channel, which is the last
declared queue.
nowait: boolean
do not send a reply method
If set, the server will not respond to the method. The
client should not wait for a reply method. If the
server could not complete the method it will raise a
channel or connection exception.
arguments: table
arguments for binding
A set of arguments for the binding. The syntax and
semantics of these arguments depends on the exchange
class.
"""
return self.send_method(
spec.Queue.Bind, argsig,
(0, queue, exchange, routing_key, nowait, arguments),
wait=None if nowait else spec.Queue.BindOk,
)
def queue_unbind(self, queue, exchange, routing_key='',
nowait=False, arguments=None, argsig='BsssF'):
"""Unbind a queue from an exchange
This method unbinds a queue from an exchange.
RULE:
If a unbind fails, the server MUST raise a connection exception.
PARAMETERS:
queue: shortstr
Specifies the name of the queue to unbind.
RULE:
The client MUST either specify a queue name or have
previously declared a queue on the same channel
RULE:
The client MUST NOT attempt to unbind a queue that
does not exist.
exchange: shortstr
The name of the exchange to unbind from.
RULE:
The client MUST NOT attempt to unbind a queue from an
exchange that does not exist.
RULE:
The server MUST accept a blank exchange name to mean
the default exchange.
routing_key: shortstr
routing key of binding
Specifies the routing key of the binding to unbind.