python通用延迟消息队列
Project description
Usage
pip install dqueue
Example
Memory Queue
# memory queue
import threading
from dqueue.queues import MemoryQueue
from dqueue.item import Item
queue = MemoryQueue()
# 模拟不同延迟发布消息
def publisher():
for i in range(10):
item = Item(data=f'hello {i}')
queue.add(item, i * 1000)
# 模拟消费端取延迟消息
def consumer():
while True:
messages = queue.get(block=10 * 1000)
for msg in messages:
print('message:', msg)
threading.Thread(target=publisher).start()
threading.Thread(target=consumer).start()
Redis Queue
You can continue with the example above and Just change the declare.
from dqueue.queues import RedisQueue
queue = RedisQueue()
# same code
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dqueue-0.1.2.tar.gz
(7.0 kB
view hashes)
Built Distribution
dqueue-0.1.2-py3-none-any.whl
(9.7 kB
view hashes)