aio pika 等待消息确认到rabbitmq时出现超时异常

发布于 2025-01-17 08:02:42 字数 1207 浏览 2 评论 0原文

我正在使用 aio pika 版本 6.7.1 和 python 3.7.7 以及rabbitmq 3.8.9。

消费者看起来像文档建议

        async with connection:
            # Creating channel
            channel = await connection.channel()
            await channel.set_qos(prefetch_count=self.prefetch_count)

            # Declaring exchange
            exchange = await channel.declare_exchange(
                'EX', ExchangeType.TOPIC, durable=True
            )

            # Declaring queue
            queue = await channel.declare_queue(self.queue_name, durable=True)

            # Bind queue to exchange
            await queue.bind(exchange)
            async with queue.iterator() as iter:
               async for message in iter:
                    try:
                       await self.do_stuff_to_message(message)
                       await message.ack()
                    except Exception as e:
                       await self.processor.handle_failure(e, message)

但是收到“asyncio.TimeoutError from None”错误 - 它只能通过从 message.ack() 中删除等待来解决。

原因是什么以及正确的使用方法是什么?

I`m using aio pika version 6.7.1 with python 3.7.7 with rabbitmq 3.8.9.

the consumer looks like the documentations suggests:

        async with connection:
            # Creating channel
            channel = await connection.channel()
            await channel.set_qos(prefetch_count=self.prefetch_count)

            # Declaring exchange
            exchange = await channel.declare_exchange(
                'EX', ExchangeType.TOPIC, durable=True
            )

            # Declaring queue
            queue = await channel.declare_queue(self.queue_name, durable=True)

            # Bind queue to exchange
            await queue.bind(exchange)
            async with queue.iterator() as iter:
               async for message in iter:
                    try:
                       await self.do_stuff_to_message(message)
                       await message.ack()
                    except Exception as e:
                       await self.processor.handle_failure(e, message)

but gets "asyncio.TimeoutError from None" errors -
its only solved by removing the await from message.ack().

what is the reason and what is the correct use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文