Routing¶
RabbitRouter¶
RabbitRouter
¶
Modular router — groups related routes with shared defaults.
Use routers to organize handlers by domain:
orders_router = RabbitRouter(prefix="orders", exchange="orders-exchange")
@orders_router.subscriber(queue="orders-queue", routing_key="created")
def handle_order(order: Order) -> None:
...
Include in broker/app:
Source code in src/rabbitkit/core/router.py
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 | |
Methods:¶
subscriber(queue: RabbitQueue | str, exchange: RabbitExchange | str | None = None, routing_key: str = '', ack_policy: AckPolicy = AckPolicy.AUTO, middlewares: list[BaseMiddleware] | None = None, serializer: Serializer[Any] | None = None, retry: RetryConfig | RetryDisabled | None = None, tags: frozenset[str] | set[str] | None = None, description: str = '', name: str | None = None, prefetch_count: int | None = None, filter_fn: Callable[[RabbitMessage], bool] | None = None, reject_without_dlx: str | None = None) -> Callable[[Callable[..., Any]], Callable[..., Any]]
¶
Register a subscriber on this router.
Applies router-level defaults: - prefix is prepended to routing_key - exchange falls back to router's default exchange - middlewares are merged (router-level + route-level) - serializer falls back to router's serializer - tags are merged (router-level + route-level)
Source code in src/rabbitkit/core/router.py
publisher(exchange: RabbitExchange | str | None = None, routing_key: str = '') -> Callable[[Callable[..., Any]], Callable[..., Any]]
¶
Register a result publisher on this router.
Source code in src/rabbitkit/core/router.py
RabbitExchange¶
RabbitExchange
dataclass
¶
Exchange declaration model.
Source code in src/rabbitkit/core/topology.py
Methods:¶
validate() -> None
¶
Validate exchange configuration.
Source code in src/rabbitkit/core/topology.py
to_declare_kwargs() -> dict[str, Any]
¶
Build exchange_declare kwargs for pika/aio-pika.
Source code in src/rabbitkit/core/topology.py
to_bind_kwargs() -> dict[str, Any] | None
¶
Build exchange_bind kwargs. Returns None if no binding.
Source code in src/rabbitkit/core/topology.py
RabbitQueue¶
RabbitQueue
dataclass
¶
Queue declaration model with type-specific validation.
Source code in src/rabbitkit/core/topology.py
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 | |
Methods:¶
validate() -> None
¶
Enforce queue-type-specific constraints.
Raises TopologyValidationError (a ValueError subclass) for invalid combinations. Uses warnings.warn() for unusual but legal combinations.
Source code in src/rabbitkit/core/topology.py
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 | |
to_declare_kwargs() -> dict[str, Any]
¶
Build queue_declare kwargs with merged x-arguments.
Source code in src/rabbitkit/core/topology.py
to_bind_kwargs(exchange: str) -> dict[str, Any]
¶
Build queue_bind kwargs.
TopologyMode¶
TopologyMode
¶
Bases: str, Enum
Topology declaration modes.
See Contract 6 in the plan for precedence rules: - AUTO_DECLARE: declare exchanges/queues/bindings on startup - PASSIVE_ONLY: all declarations use passive=True - MANUAL: skip all topology operations
Source code in src/rabbitkit/core/types.py
TopologyDispatcher¶
TopologyDispatcher
¶
Resolves TopologyMode into a concrete TopoAction per entity.
The transport computes to_declare_kwargs() and performs the actual
(sync or async) channel call based on the returned TopoAction,
keeping all transport-specific I/O out of this class.
Source code in src/rabbitkit/core/topology_dispatch.py
Attributes¶
mode: TopologyMode
property
¶
The topology mode this dispatcher was configured with.
Methods:¶
exchange_action(exchange: RabbitExchange) -> TopoAction
¶
Action to take for declare_exchange(exchange).
Source code in src/rabbitkit/core/topology_dispatch.py
queue_action(queue: RabbitQueue) -> TopoAction
¶
Action to take for declare_queue(queue).
Source code in src/rabbitkit/core/topology_dispatch.py
binding_action() -> TopoAction
¶
Action to take for bind_queue / bind_exchange.
Bindings have no passive variant — they are skipped only under
MANUAL and performed otherwise.
Source code in src/rabbitkit/core/topology_dispatch.py
TopoAction
¶
Bases: Enum
What the transport should do for a topology entity.