Skip to main content

django-eventhandler

This is an event handler that handles messages from an AMQP server, installable as a Django application. Events are JSON-encoded dicts that have a key called ‘type’. The eventhandler calls functions that have bound themselves to an event using a decorator.

Installation and configuration

Install the application in your Django project. Add ‘eventhandler’ to your INSTALLED_APPS setting. Then, add the following two settings to your project settings file.

LISTENER_URL = 'amqps://<user>:<pass>@<hostname>/<vhost>'
LISTENER_QUEUE = 'my-application'

Optionally, you can also specify these three settings, to have an exchange declared.

LISTENER_EXCHANGE = 'events'
LISTENER_EXCHANGE_TYPE = 'topic'
LISTENER_ROUTING_KEY = '#'

Running the event handler

Manually: python manage.py event_listener. To daemonize it, you can use something like supervisor to manage the process.

Usage

Events that are received from AMQP should be JSON-encoded dicts. Each message should have a key named type, with str value. This value can be used in a decorator, to have the event handler execute a function when receiving an event.

Example:

from eventhandler import handles_event

@handles_event('my_event')
def do_something_clever(event):
    pass

Now each event with a ‘type’: ‘my_event’ combo will be passed into this function. Of course it’s possible to have more than one handler for an event, or have one handler handle multiple events.

from eventhandler import handles_event

@handles_event('my_other_event')
@handles_event('my_event')
def do_something_clever(event):
    pass

@handles_event('my_other_event')
def do_something_else(event):
    pass
NB Make sure that your handlers are in a place that’s loaded/scanned on startup of Django,

otherwise the decorators won’t register the handlers. For instance, for a Django-application, my_app/__init__.py is scanned on startup (provided my_app is in INSTALLED_APPS). So if your handlers are in my_app/events.py, you could load them from there:

# my_app/__init__.py:

# Load handlers for events, so django-eventhandlers picks 'em up
import my_app.events  # NOQA (keep pyflakes happy)

Running tests

Just run python manage.py test to run tests against your current setup. Run tox to run tests for various versions of Django. Currently, Django 1.6 through 1.9 on Python 2.7 are tested.

About

This software is brought to you by Byte, a webhosting provider based in Amsterdam, The Netherlands. We specialize in fast and secure Magento hosting and scalable cluster hosting.

Check out our Github page for more open source software or our site to learn about our products and technologies. Look interesting? Reach out about joining the team. Or just drop by for a cup of excellent coffee if you’re in town!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-eventhandler-0.4.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_eventhandler-0.4.1-py2-none-any.whl (5.2 kB view details)

Uploaded Python 2

File details

Details for the file django-eventhandler-0.4.1.tar.gz.

File metadata

File hashes

Hashes for django-eventhandler-0.4.1.tar.gz
Algorithm Hash digest
SHA256 424a7a37898f403da8a0166f91fee6a248b9ae559536e41f41507b4f71c35611
MD5 7a50606b76bf98483530db91af84fc80
BLAKE2b-256 7d74467f646f96408e8d23670433832a04687e3e7b0e07cbe153544912588c54

See more details on using hashes here.

File details

Details for the file django_eventhandler-0.4.1-py2-none-any.whl.

File metadata

File hashes

Hashes for django_eventhandler-0.4.1-py2-none-any.whl
Algorithm Hash digest
SHA256 ada4d325246907841344c195d5f420156712146d4393fada709f1984291532d2
MD5 cad349983f56f6a70ec049cb23102745
BLAKE2b-256 b5d5b4844475d47760ac90fef3231788a7ba5c724e4f3e604f7539ef7132b37d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page