44from .qpid .proton ._delivery import Delivery
55from .qpid .proton ._events import Event
66
7+ '''
8+ DeliveryContext is a class that is used to accept, reject, requeue or requeue with annotations a message.
9+ It is an helper to set the default values needed for manually accepting and settling messages.
10+ '''
11+
712
813class DeliveryContext :
14+ """
15+ Accept the message (AMQP 1.0 <code>accepted</code> outcome).
16+
17+ This means the message has been processed and the broker can delete it.
18+ """
919
1020 def accept (self , event : Event ) -> None :
1121 dlv = event .delivery
1222 dlv .update (Delivery .ACCEPTED )
1323 dlv .settle ()
1424
25+ """
26+ Reject the message (AMQP 1.0 <code>rejected</code> outcome).
27+ This means the message cannot be processed because it is invalid, the broker can drop it
28+ or dead-letter it if it is configured.
29+ """
30+
1531 def discard (self , event : Event ) -> None :
1632 dlv = event .delivery
1733 dlv .update (Delivery .REJECTED )
1834 dlv .settle ()
1935
36+ """
37+ Discard the message with annotations to combine with the existing message annotations.
38+ This means the message cannot be processed because it is invalid, the broker can drop it
39+ or dead-letter it if it is configured.
40+ Application-specific annotation keys must start with the <code>x-opt-</code> prefix.
41+ Annotation keys the broker understands starts with <code>x-</code>, but not with <code>x-opt-
42+
43+ This maps to the AMQP 1.0
44+ modified{delivery-failed = true, undeliverable-here = true}</code> outcome.
45+ <param name="annotations"> annotations message annotations to combine with existing ones </param>
46+ <a
47+ href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-modified">AMQP
48+ 1.0 <code>modified</code> outcome</a>
49+
50+ The annotations can be used only with Quorum queues, see https://www.rabbitmq.com/docs/amqp#modified-outcome
51+ """
52+
2053 def discard_with_annotations (
21- self , event : Event , annotations : Dict [str , "PythonAMQPData" ]
54+ self , event : Event , annotations : Dict [str , "PythonAMQPData" ]
2255 ) -> None :
2356 dlv = event .delivery
2457 dlv .local .annotations = annotations
@@ -28,13 +61,39 @@ def discard_with_annotations(
2861 dlv .update (Delivery .MODIFIED )
2962 dlv .settle ()
3063
64+ """
65+ Requeue the message (AMQP 1.0 <code>released</code> outcome).
66+ This means the message has not been processed and the broker can requeue it and deliver it
67+ to the same or a different consumer.
68+ """
69+
3170 def requeue (self , event : Event ) -> None :
3271 dlv = event .delivery
3372 dlv .update (Delivery .RELEASED )
3473 dlv .settle ()
3574
75+ """
76+ Requeue the message with annotations to combine with the existing message annotations.
77+
78+ This means the message has not been processed and the broker can requeue it and deliver it
79+ to the same or a different consumer.
80+ Application-specific annotation keys must start with the <code>x-opt-</code> prefix.
81+ Annotation keys the broker understands starts with <code>x-</code>, but not with <code>x-opt-
82+ </code>.
83+
84+ This maps to the AMQP 1.0 <code>
85+ modified{delivery-failed = false, undeliverable-here = false}</code> outcome.
86+
87+ <param name="annotations"> annotations message annotations to combine with existing ones </param>
88+ <a
89+ href="https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-modified">AMQP
90+ 1.0 <code>modified</code> outcome</a>
91+
92+ The annotations can be used only with Quorum queues, see https://www.rabbitmq.com/docs/amqp#modified-outcome
93+ """
94+
3695 def requeue_with_annotations (
37- self , event : Event , annotations : Dict [str , "PythonAMQPData" ]
96+ self , event : Event , annotations : Dict [str , "PythonAMQPData" ]
3897 ) -> None :
3998 dlv = event .delivery
4099 dlv .local .annotations = annotations
0 commit comments