Skip to main content

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


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)

Uploaded Source

Built Distribution

dqueue-0.1.2-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page