Skip to main content

Mixin for publishing events to RabbitMQ

Project description

AMQP Publishing Mixin for Tornado RequestHandlers.

Version Downloads Travis CodeCov Docs

Installation

sprockets.mixins.amqp is available on the Python Package Index and can be installed via pip or easy_install:

pip install sprockets.mixins.amqp

Documentation

https://pythonhosted.org/sprockets.mixins.amqp

Requirements

  • pika>=0.10.0

  • tornado>=4.2.0

Example

This examples demonstrates the most basic usage of sprockets.mixins.amqp

export AMQP_URL="amqp://user:password@rabbitmq_host:5672/%2f"
python my-example-app.py
import json

from tornado import gen, web
from sprockets.mixins import amqp

def make_app(**settings):
    application = web.Application(
        [
            web.url(r'/', RequestHandler),
        ], **settings)

    amqp.install(application)
    return application


class RequestHandler(amqp.PublishingMixin, web.RequestHandler):

    @gen.coroutine
    def get(self, *args, **kwargs):
        body = {'request': self.request.path, 'args': args, 'kwargs': kwargs}
        yield self.amqp_publish('exchange', 'routing.key', json.dumps(body),
                                {'content_type': 'application/json'})

Settings

url:

The AMQP url

timeout:

The connect timeout, in seconds, if the connection when you try to publish.

connection_attempts:

The maximum number of retry attempts in case of connection errors.

Source

sprockets.mixins.amqp source is available on Github at https://github.com/sprockets/sprockets.mixins.amqp

License

sprockets.mixins.amqp is released under the 3-Clause BSD license.

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

sprockets.mixins.amqp-1.0.1.tar.gz (6.2 kB view hashes)

Uploaded Source

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