包装多个后端以提供一致的pubsub api的通用接口。
aio-pubsub的Python项目详细描述
包装多个后端以提供一致的pubsub api的通用接口。
用法
要使用它,您需要从接口实现pubsub实现或使用后端 来自aio_pubsub.backends包:
from aio_pubsub.backends.memory import MemoryPubSub pubsub = MemoryPubSub() # Create subscriber subscriber = await pubsub.subscribe("a_chan") # Push message await pubsub.publish("a_chan", "hello world!") await pubsub.publish("a_chan", "hello universe!") # And listening channel try: async for message in subscriber: print(message, flush=True) except KeyboardInterrupt: print("Finish listening")
支持的后端
Disclaimer:我不建议您使用这个后端,因为它只显示用于测试目的。 更好地开发自己的实现。
- 内存
- MongoDB
- redis