Graceful Shutdown¶
TypedBus provides several levels of cleanup for stopping channels and buses.
Close a Channel¶
Stops accepting new publishes and subscribes. Pending deliveries are force-NACKed and routed to the DLQ.
After closing:
publishraisesRuntimeError, including for publishers that were already waiting onmax_pendingor throttle whencloseran: they wake up and raiseChannel :name is closedinstead of deliveringsubscriberaisesRuntimeError- The DLQ retains its entries for inspection
If an on_dead_letter callback raises during the force-nack, every pending delivery is still nacked and the first error is re-raised once they are all handled. Call close inside a begin/rescue if your callback can fail.
Close All Channels¶
Closes every channel on the bus. Each channel's pending deliveries are force-NACKed. If closing one channel raises, the others are still closed and the first error is re-raised afterwards.
Clear a Channel¶
Hard reset: cancels all timeout tasks, discards pending deliveries, and clears the DLQ.
Unlike close, clear! does not mark the channel as closed — you can continue using it.
Clear a Bus¶
Clears all channels and resets stats:
Remove a Channel¶
Close and remove a channel from the bus registry:
Removing a nonexistent channel is a no-op.
Shutdown Order¶
For a clean shutdown:
- Stop publishing new messages
- Wait for pending deliveries to resolve (or let timeouts fire)
- Process any DLQ entries
- Call
bus.close_all