Skip to main content

AMQP Publishing Mixin for Tornado RequestHandlers.

Version Downloads Build Status CodeCov Docs

Installation

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

pip3 install sprockets.mixins.amqp

Documentation

https://sprocketsamqp.readthedocs.io

Python Compatibility

  • Python 3.7

  • Python 3.8

Requirements

  • Pika==0.13.1

  • Tornado>=6,<7

Example

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"
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_settings = {
        "reconnect_delay": 5,
    }

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


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

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

AMQP Settings

url:

The AMQP URL to connect to.

reconnect_delay:

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.

connection_attempts:

The optional number of connection attempts to make before giving up.

on_ready_callback:

The optional callback to call when the connection to the AMQP server has been established and is ready.

on_unavailable_callback:

The optional callback to call when the connection to the AMQP server becomes unavailable.

on_persistent_failure_callback:

The optional callback to call when the connection failure does not resolve itself within the timeout.

on_message_returned_callback:

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()

  • AMQP_URL

  • AMQP_TIMEOUT

  • AMQP_RECONNECT_DELAY

  • AMQP_CONNECTION_ATTEMPTS

Source

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

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) $ ./bootstrap.sh
(env) $ coverage run && coverage report

License

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

Release files for sprockets.mixins.amqp 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sprockets.mixins.amqp 3.0.1
File Size Uploaded
sprockets.mixins.amqp-3.0.1.tar.gz 12.2 kB Details

Release files / sprockets.mixins.amqp-3.0.1.tar.gz

Download URL sprockets.mixins.amqp-3.0.1.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5eac98305e33f6aa44c14c94e59911ac22e3781a1dc7ff4b94ba86c41bd620b2
BLAKE2b-256 checksum
How to use checksums
55c31433b89118e0a322b19409c1460ea56c598d525f6214391c8853d169b3a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

3.0.1 This release

1 release file

3.0.0

1 release file

2.2.0

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

1 release file

1.0.1

1 release file

1.0.0

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page