Messages & Settlement¶
RabbitMessage¶
RabbitMessage
¶
Rich incoming message with transport-aware settlement.
The message object wraps raw AMQP delivery data and provides: - Typed access to headers, properties, routing info - Sync and async ack/nack/reject methods - Idempotent settlement (double-ack is a no-op) - Topic wildcard path extraction
Source code in src/rabbitkit/core/message.py
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 | |
Attributes¶
is_settled: bool
property
¶
True if the message has been acked, nacked, or rejected.
disposition: str
property
¶
Final settlement state: "pending", "acked", "nacked", or "rejected" (M2).
Methods:¶
ack() -> None
¶
Synchronous ack. Raises SettlementError on async-only transport.
Sets disposition only after the transport call succeeds, so a failed ack (channel closed, frame error) leaves the message unsettled and the exception propagates to the recovery loop instead of being swallowed.
Source code in src/rabbitkit/core/message.py
nack(requeue: bool = True) -> None
¶
Synchronous nack. Raises SettlementError on async-only transport.
Source code in src/rabbitkit/core/message.py
reject(requeue: bool = False) -> None
¶
Synchronous reject. Raises SettlementError on async-only transport.
Source code in src/rabbitkit/core/message.py
ack_async() -> None
async
¶
Async ack. Falls back to sync if async fn not set.
Source code in src/rabbitkit/core/message.py
nack_async(requeue: bool = True) -> None
async
¶
Async nack. Falls back to sync if async fn not set.
Source code in src/rabbitkit/core/message.py
reject_async(requeue: bool = False) -> None
async
¶
Async reject. Falls back to sync if async fn not set.
Source code in src/rabbitkit/core/message.py
MessageEnvelope¶
MessageEnvelope
dataclass
¶
Outgoing message envelope.
NOTE: AMQP header values are limited to: str, int, float, bool, bytes, datetime, Decimal, list/dict of these, or None. Arbitrary Python objects (sets, custom classes) will raise at publish time. Transport validates header values before sending.
Source code in src/rabbitkit/core/types.py
AckPolicy¶
AckPolicy
¶
Bases: str, Enum
Message acknowledgement policies.
See Contract 1 in the plan for exact semantics: - AUTO: success→ack, exception→classify→nack/reject - MANUAL: handler owns ack/nack/reject entirely - NACK_ON_ERROR: success→ack, exception→nack(requeue=False) - ACK_FIRST: ack BEFORE handler runs (at-most-once)
Source code in src/rabbitkit/core/types.py
AckStrategy¶
AckStrategy
¶
Bases: Protocol
Settlement strategy for an AckPolicy.
Each strategy owns the success-path ack and the error-path settlement.
Handler-raised AckMessage / NackMessage / RejectMessage are
NOT policy-driven and stay in the pipeline.
See Contract 1 in the plan for per-policy semantics.
Source code in src/rabbitkit/core/types.py
PublishOutcome / PublishStatus¶
PublishOutcome
dataclass
¶
Result of a publish operation.
Source code in src/rabbitkit/core/types.py
Attributes¶
ok: bool
property
¶
True if the publish did not fail -- CONFIRMED (broker acknowledged it) or SENT (fire-and-forget, confirm_delivery=False -- written to the socket but never broker-confirmed).
M4: if you specifically need to know the broker actually confirmed
the message (e.g. before treating a republish as durable enough to
settle/discard the original), check status ==
PublishStatus.CONFIRMED directly -- .ok alone can't
distinguish "confirmed" from "sent, unconfirmed."
classification: ClassifiedError | None
property
¶
Best-effort severity/reason for self.error, via the existing
classify_error() (production-hardening item 5).
Deliberately NOT a new PublishStatus enum member: growing that
small, closed "what happened" set (CONFIRMED/SENT/NACKED/TIMEOUT/
RETURNED/ERROR) risks breaking exhaustive match/if-chains callers
may have written against it, for a "why" signal better served by
reusing the classification machinery already wired into the
consume/retry path (core/errors.py) rather than duplicating it.
A lazy import avoids a module-level cycle (core/errors.py
already imports from this module) — same pattern as
:meth:raise_for_status.
None when there's nothing to classify: a non-ERROR status, or
an ERROR outcome that (unusually) captured no exception.
Methods:¶
raise_for_status() -> PublishOutcome
¶
Raise PublishError if the publish failed; else return self (M1).
broker.publish() never raises — it returns this outcome so a
failed publish (NACKED / TIMEOUT / RETURNED / ERROR) can't be lost by
code that simply ignores the return value. Callers who prefer
exceptions opt in::
broker.publish(envelope).raise_for_status()
Chains so outcome = broker.publish(...).raise_for_status() works.
Source code in src/rabbitkit/core/types.py
PublishStatus
¶
Bases: str, Enum
Result status of a publish operation.