Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/patrys/pymongo-pubsub
a publish-subscribe pattern implementation for pymongo
https://github.com/patrys/pymongo-pubsub
Last synced: 11 days ago
JSON representation
a publish-subscribe pattern implementation for pymongo
- Host: GitHub
- URL: https://github.com/patrys/pymongo-pubsub
- Owner: patrys
- Archived: true
- Created: 2012-03-09T21:30:25.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-01-11T07:02:43.000Z (almost 8 years ago)
- Last Synced: 2024-08-01T22:57:04.282Z (3 months ago)
- Language: Python
- Homepage: http://room-303.com/blog/
- Size: 5.86 KB
- Stars: 29
- Watchers: 2
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
pymongo-pubsub — a publish-subscribe pattern implementation for pymongo
=======================================================================Ever wished you could use your MongoDB to drive an event-driven environment?
Now you can.
pymongo-pubsub uses a round-robin *capped* collection to store its data on one
end and a *tailable* cursor to catch it as it is inserted on the other.The publisher
-------------A publisher is a piece of code responsible for pumping data into the database:
```python
import pymongo
from pymongo_pubsub import Publisherconnection = pymongo.Connection()
database = connection.pubsub_dbpublisher = Publisher(database, 'test_event')
publisher.push({'message': 'hello world', 'answer': 42})
```A `Publisher` will take care of setting up the underlying collection. You can
pass it optional `max_size` and `max_length` parameters to define storage
limits of the collection at the time it is created. The default size is
`1000000` bytes and the default length limit is `None`.Make sure your queue is big enough to never overflow or you're going to start
losing data. You care about your data, right?The subscriber
--------------A subscriber is a piece of code responsible for processing data as it is pulled
from the database:```python
import pymongo
from pymongo_pubsub import Subscriberconnection = pymongo.Connection()
database = connection.pubsub_dbdef test_cb(data):
print '{0:f}: {1:s}'.format(data['_id'], data['message'])subscriber = Subscriber(database, 'test_event', callback=test_cb,
matching={'answer': 42})
subscriber.listen()
```A `Subscriber` will never create any collections in the database and in case
the collections is missing it will cowardly raise a `KeyError` exception.
This is not a bug. This is to avoid having to synchronize collection limits
between the publisher and all of the subscribers.