Skip to main content

Mixin for publishing events to RabbitMQ

Project description

AMQP Publishing Mixin for Tornado RequestHandlers.

Version Downloads Build Status CodeCov Docs


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

pip3 install sprockets.mixins.amqp

Python Compatibility

  • Python 3.7
  • Python 3.8


  • Pika==0.13.1
  • Tornado>=6,<7


You may optionally install sprockets.mixins.correlation into your request handler to take advantage of automatic correlation_id fetching. Otherwise, be sure to set correlation_id as an instance variable on your request handler before sending AMQP messages.

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

export AMQP_URL="amqp://user:password@rabbitmq_host:5672/%2f"
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_settings = {
        "reconnect_delay": 5,

    amqp.install(application, **amqp_settings)
    return application

class RequestHandler(amqp.PublishingMixin,

    async def get(self, *args, **kwargs):
        body = {'request': self.request.path, 'args': args, 'kwargs': kwargs}
        await self.amqp_publish(
            {'content_type': 'application/json'}

AMQP Settings

url:The AMQP URL to connect to.
 The optional time in seconds to wait before reconnecting on connection failure.
timeout:The optional maximum time to wait for a bad state to resolve before treating the failure as persistent.
 The optional number of connection attempts to make before giving up.
 The optional callback to call when the connection to the AMQP server has been established and is ready.
 The optional callback to call when the connection to the AMQP server becomes unavailable.
 The optional callback to call when the connection failure does not resolve itself within the timeout.
 The optional callback to call when the AMQP server returns a message.
ioloop:An optional IOLoop to override the default with.

Environment Variables

Any environment variables set will override the corresponding AMQP settings passed into install()



sprockets.mixins.amqp source is available on Github at

Running Tests Locally

You’ll need to have python 3.7, Docker and Docker Compose installed.

$ python3 -m venv env
$ env/bin/activate
(env) $ pip3 install -r requires/testing.txt
(env) $ ./
(env) $ coverage run && coverage report


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

Download files

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

Files for sprockets.mixins.amqp, version 3.0.1
Filename, size File type Python version Upload date Hashes
Filename, size sprockets.mixins.amqp-3.0.1.tar.gz (12.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page