diff --git a/docs/source/examples/pooling-recycled.py b/docs/source/examples/pooling-recycled.py index 6e339655..65343778 100644 --- a/docs/source/examples/pooling-recycled.py +++ b/docs/source/examples/pooling-recycled.py @@ -1,5 +1,3 @@ -from collections import defaultdict - import asyncio import aio_pika from aio_pika.pool import Pool @@ -12,8 +10,8 @@ class NonRestoringRobustChannel(aio_pika.RobustChannel): """ async def reopen(self) -> None: # Clear out exchanges and queues when reopened - self._exchanges = defaultdict(set) - self._queues = defaultdict(set) + self._exchanges.clear() + self._queues.clear() await super().reopen() diff --git a/docs/source/quick-start.rst b/docs/source/quick-start.rst index ddaf8054..9c25fe1b 100644 --- a/docs/source/quick-start.rst +++ b/docs/source/quick-start.rst @@ -55,5 +55,12 @@ Connection pooling Connection pooling with recycled channels ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +When channels are re-used from a pool where queues and exchanges are not +consistent (i.e. the first time a channel is checked out it creates and uses +queue1 and the next time it is checked out it creates and uses queue2), it +is necessary to clear queues and exchanges before attempting to use the +channel. This is done with custom Connection and Channel classes and by +calling ``reopen`` on channel checkout if it was closed. + .. literalinclude:: examples/pooling-recycled.py :language: python