首页 > 解决方案 > 返回rabbitmq交换声明,队列声明和队列绑定ok

问题描述

我对 rabbitmq 和 asyncio 很陌生。我想在此处的rabbitmq示例代码之后编写一个初始化函数 https://github.com/pika/pika/blob/master/examples/asynchronous_publisher_example.py

在示例代码中,它使用一个回调链来声明交换、声明队列和绑定队列。这正是我想要在我的初始化功能中实现的。我想知道是否有可能在绑定队列正常之后,也就是执行此回调时,使用 asyncio 以某种方式“获得通知”。https://github.com/pika/pika/blob/master/examples/asynchronous_publisher_example.py#L214 并返回我的初始化函数。

我不想使用 BlockingChannel,因为我正在修改一些现有代码,这不是一个选项。

非常感谢大家!

最小的代码集可以是这样的

def initialize(self):
   self.declare_exchange()
   # wait for queue bind ok, how to do?
   return 

def declare_exchange(self):
   self.channel.exchange_declare(
     ....
     callback = self.declare_queue
   )

def declare_queue(self):
   self.channel.queue_declare(
     ...
     callback = self.bind_queue
   )

def bind_queue(self):
   self.channel.queue_bind(
     ...
     callback = self.queue_bind_ok
   )


def queue_bind_ok(self):
   # notify initialization done, how to do?

标签: rabbitmqpython-asyncio

解决方案


推荐阅读