You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(routing): tighten router contracts after review
Remove direct router access to broker private task storage and add an explicit
broker-owned storage boundary for router-managed task registration.
Clarify prepared route snapshots, subscription task-name semantics and setup-time
router mutation contracts. Extend routing docs with flow resolution precedence
and custom task base class middleware behavior.
Add regression coverage for shared task local registration, custom base_cls
middleware hooks and scheduler fallback when a route is removed before dispatch.
Copy file name to clipboardExpand all lines: docs/guide/routing-and-flows.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -150,6 +150,16 @@ keep a snapshot of the route that was resolved at prepare time, so later changes
150
150
to the mutable kicker object or router route table do not change that prepared
151
151
send.
152
152
153
+
Flow selection is resolved in this order:
154
+
155
+
| Source | Effect |
156
+
| --- | --- |
157
+
| Explicit route |`.with_route(route)` uses that route's broker and flow. A later `.with_flow(flow)` updates the route flow, while a later `.with_broker(broker)` clears the explicit route. |
158
+
| Explicit broker |`.with_broker(broker)` sends through that broker. If `.with_flow(flow)` is also set, that flow wins; otherwise Taskiq uses the same-broker task route flow, then the broker `default_flow`. |
159
+
| Explicit flow |`.with_flow(flow)` without a broker override replaces the flow of the resolved route or broker default route. |
160
+
| Router task route |`router.route_task(task, broker=..., flow=...)` is the default outbound route for that task. |
161
+
| Broker default flow |`InMemoryBroker(..., default_flow=...)` and other brokers with `default_flow` provide the fallback flow for that broker. |
162
+
153
163
## Subscriptions
154
164
155
165
Routers also keep inbound flow subscriptions. Routing and subscribing are
@@ -179,6 +189,11 @@ The deprecated `route_task(..., subscribe=True)` shim still performs this
179
189
subscription when a flow is resolved, but new code should call `subscribe()`
180
190
directly.
181
191
192
+
`TaskiqSubscription.task_names` is diagnostic listen-plan metadata. It records
193
+
which task names caused the broker to listen to a flow, but it does not make the
194
+
flow an inbound task router. Workers still execute messages by
195
+
`TaskiqMessage.task_name`.
196
+
182
197
Existing brokers can keep implementing `listen()` as before. New flow-aware
183
198
brokers may use `get_subscribed_flows()` to subscribe to queues, topics,
184
199
subjects or streams while the routing rules stay in the router.
@@ -187,6 +202,10 @@ subjects or streams while the routing rules stay in the router.
187
202
subscriptions. It deduplicates by flow identity and checks broker options for
188
203
conflicts.
189
204
205
+
Router routes and subscriptions are mutable setup-time configuration. They are
206
+
not thread-safe runtime coordination primitives; configure them before starting
207
+
concurrent worker or client activity.
208
+
190
209
## Scheduler and requeue
191
210
192
211
`ScheduledTask` remains a transport-neutral invocation payload. It stores task
@@ -277,6 +296,9 @@ When the final application registers this definition, Taskiq creates the bound
277
296
task using `TracingTask`. If `base_cls` is not provided, Taskiq uses the native
278
297
decorated task class.
279
298
299
+
Custom task classes do not bypass broker middleware. Send and execute lifecycle
300
+
hooks are still owned by the selected broker and worker path.
301
+
280
302
For low-level integrations, `TaskDefinition.message(...)` builds a
281
303
`TaskiqMessage` without binding the task. It uses the same argument and label
282
304
preparation contract as a normal `.kicker().prepare(...)` invocation.
0 commit comments