mosquito / aio-pika

AMQP 0.9 client designed for asyncio and humans.
https://aio-pika.readthedocs.org/
Apache License 2.0
1.18k stars 186 forks source link

Channel is closed #580

Open mofibo opened 9 months ago

mofibo commented 9 months ago

Hello lads,

I just want to know if there is a specific time to publish the message after reading it when using aiopika, because when i tried a process that takes a few time, I get "channel is closed" when publishing the message, here is a part of a test code I used:

    async def connect(self):
        self.connection = await connect_robust(
            host=RABBITMQ_HOST,
            port=RABBITMQ_PORT,
            login=USERNAME,
            password=PASSWORD_RMQ,
            virtualhost=VIRTUAL_HOST,
            loop=self.loop,
        )

        # Creating a channel
        self.channel = await self.connection.channel()
        await self.channel.set_qos(1)

        # Declaring queue
        self.queue = await self.channel.declare_queue(
            env_var.MAIN_QUEUE, arguments={"x-message-ttl": self.TTL_VALUE}
        )

        await self.queue.consume(
            partial(self.on_message, self.channel.default_exchange)
        )

        return 
async def on_message(self, exchange: Exchange, message: IncomingMessage):
        with message.process():
                    time.sleep(200) # this is to replace the process, so i can get "channel is closed" 
                    await exchange.publish(
                        Message(
                            body=output_msg.SerializeToString(),
                            correlation_id=message.correlation_id,
                        ),
                        routing_key=message.reply_to,
                    )

For what reason the publish doesn't work and i receive channel is close? I'm using aio-pika 6.8.1

Thank you in advance. Regards