AMQP support for Sanic framework
Project description
Forked from and based on https://github.com/Relrin/sanic-amqp-extension (sanic-amqp-extension) Extensions were forked and modified to keep the code updated with the latest version of dependecnies and to add additional functionality
sanic-amqp
AMQP support for Sanic framework
Features
Based on the aioamqp library
Provides an opportunity to implement workers that works in background
Installation
This package should be installed using pip:
pip install sanic-amqp
Example
from sanic import Sanic, response
from sanic_amqp import AmqpExtension, AmqpWorker
app = Sanic(__name__)
# Configuration for RabbitMQ
app.config.update({
"AMQP_USERNAME": "guest",
"AMQP_PASSWORD": "guest",
"AMQP_HOST": "localhost",
"AMQP_PORT": 5672,
"AMQP_VIRTUAL_HOST": "vhost",
"AMQP_USING_SSL": False,
})
AmqpExtension(app) # AMQP is available as `app.amqp` or `app.extensions['amqp']`
class CustomWorker(AmqpWorker):
async def run(self, *args, **kwargs):
transport, protocol = await self.connect() # create a new connection
# and do some stuff here ...
# Register workers after initializing the extension
app.amqp.register_worker(CustomWorker(app))
@app.route("/")
async def handle(request):
transport, protocol = await request.app.amqp.connect() # create a new connection
# do some stuff here ...
# P.S. but don't forget to close the connection after using
return response.text("It's works!")
License
The sanic-amqp is published under BSD license. For more details read LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sanic-amqp-0.1.0.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for sanic_amqp-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5af2b5f5d6fe6608f659aeb565a31856f806dd96fbdf3ebab5cbf26bd1024fd1 |
|
MD5 | a32f5b3d24f3448bc594c111567c1af9 |
|
BLAKE2b-256 | 2cc1f59017d9448c363d49c37649f365356bdf4ef6bdfb098da46c4d5c4007ee |