Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Relrin/sanic-amqp-extension
AMQP support for Sanic framework
https://github.com/Relrin/sanic-amqp-extension
amqp extension python sanic
Last synced: 30 days ago
JSON representation
AMQP support for Sanic framework
- Host: GitHub
- URL: https://github.com/Relrin/sanic-amqp-extension
- Owner: Relrin
- License: bsd-3-clause
- Created: 2018-03-03T11:05:24.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-20T10:05:24.000Z (almost 2 years ago)
- Last Synced: 2024-11-07T14:22:48.932Z (about 1 month ago)
- Topics: amqp, extension, python, sanic
- Language: Python
- Size: 9.77 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
- awesome-sanic - Sanic-amqp-extension
README
sanic-amqp-extension
####################
AMQP support for Sanic frameworkFeatures
========
- Based on the aioamqp_ library
- Provides an opportunity to implement workers that works in backgroundInstallation
============
This package should be installed using pip: ::pip install sanic-amqp-extension
Example
=======
.. code-block:: pythonfrom sanic import Sanic, response
from sanic_amqp_ext import AmqpExtension, AmqpWorkerapp = 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-extension is published under BSD license. For more details read LICENSE_ file... _links:
.. _aioamqp: http://aioamqp.readthedocs.io/
.. _LICENSE: https://github.com/Relrin/sanic-amqp-extension/blob/master/LICENSEReal project examples
=====================
Open Matchmaking project:- `Auth/Auth microservice `_
- `Game servers pool microservice `_
- `Player statistics microservice `_