API Reference

class monqueue.MonQueue(name, host='localhost', port=27017, db_name='monqueue', coll_name=None, multi_queue_in_one_coll=False)

MonQueue is a Python library that allows you to use MongoDB as a message queue

clear()

clear the queue

empty

Check the queue, return True if the queue empty.

Return type

True or False

get(block=True, timeout=None)

Get one message from queue and remove it.

Parameters
  • block – blocking mode

  • timeout – depend block mode

>>> queue.get()
u'it is a message'
>>> queue.get()
{u'city': u'Chengdu', u'name': u'Rex Zhang', u'country': u'China'}
TODO

raise Empty

peek(timestamp=False, mongo_id_str=False)

Peek oldest message info. just peek, no pop.

Return type

(message object, dict object)

>>> q.put('queue msg')
>>> q.peek()
('queue msg', {})
>>> q.peek(timestamp=True)
('queue msg', {'timestamp': datetime.datetime(2015, 2, 4, 5, 58, 37, tzinfo=<bson.tz_util.FixedOffset object at 0x101389d90>)})
>>> q.peek(mongo_id_str=True)
('queue msg', {'mongo_id_str': '54d1b50ddd7215c3b15ed992'})
put(msg)

Put one message into queue. Example:

>>> queue.put('it is a message')
>>> queue.put({'name': 'Rex Zhang', 'city': 'Chengdu', 'country': 'China'})
>>> queue.put([1, 2, 3])
qsize()

Get the queue’s size.

Return type

int