排队的客户机。
pyqueued的Python项目详细描述
http消息队列的python客户端已排队:https://github.com/scttnlsn/queued。
用法
>>> import pyqueued
找个客户。
>>> client = pyqueued.Client(host='localhost', port=5353)
将消息排队:
>>> loc = client.enqueue("q", "my message") >>> loc 'http://localhost:5353/q/155'
排在队伍的最前面。在没有任何超时的情况下,项目在退出队列时标记为已完成。
>>> msg, loc = client.dequeue("q") >>> msg 'my message'
队列现在为空,因此另一个出列将失败:
>>> msg, loc = client.dequeue("q") ... RuntimeError: dequeue failed: <Response [404]>
将另一条消息排队:
>>> loc = client.enqueue("q", "another message")
但在超时的情况下出列(以秒为单位)。如果消息未在超时时间内完成, 它将再次排队。
>>> client.dequeue("q", timeout=2) ('another message', 'http://localhost:5353/q/160')
HAS消息超时,已重新排队。这样我们就可以再次出列了。但现在我们 及时完成。
>>> client.dequeue("q", timeout=20) ('my message with timeout', 'http://localhost:5353/q/160')>>> client.complete("q", "160")
或者,项目可以通过url完成。最后一行也写为:
>>> client.complete_by_url('http://localhost:5353/q/160')
有关队列的统计信息:
>>> client.stats("q") {'depth': 1, 'dequeued': 3, 'enqueued': 3, 'timeouts': 1}