Adds Rabbitmq support to your Flask application.
Project description
Flask-Rabmq
Flask-Rabmq is an extension for Flask that adds support for Rabbitmq to your application. It aims to simplify using Rabbitmq with Flask by providing useful defaults and extra helpers that make it easier to accomplish common tasks.
Installing
Install and update using pip
:
$ pip install -U Flask-Rabmq
A Simple Example
import logging
from flask import Flask
from flask_rabmq import RabbitMQ
logging.basicConfig(format='%(asctime)s %(process)d,%(threadName)s %(filename)s:%(lineno)d [%(levelname)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.INFO)
logger = logging.getLogger(__name__)
app = Flask(__name__)
app.config.setdefault('RABMQ_RABBITMQ_URL', 'amqp://username:password@ip:port/dev_vhost')
app.config.setdefault('RABMQ_SEND_EXCHANGE_NAME', 'flask_rabmq')
app.config.setdefault('RABMQ_SEND_EXCHANGE_TYPE', 'topic')
ramq = RabbitMQ()
ramq.init_app(app=app)
@app.route('/')
def hello_world():
ramq.send({'message_id': 222222, 'a': 7}, routing_key='flask_rabmq.test', exchange_name='flask_rabmq')
return 'Hello World!'
@ramq.queue(exchange_name='flask_rabmq', routing_key='flask_rabmq.test')
def flask_rabmq_test(body):
logger.info(body)
return True
if __name__ == '__main__':
app.run()
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
flask_rabmq-0.0.8.tar.gz
(4.0 kB
view hashes)