Skip to main content

Enhance RabbitMQ services for a Python Django application

Project description

django_rabbitmq_utils

To enhance the RabbitMQ library features in Python Django, to utilize additional libraries and features that complement RabbitMQ's functionality.

requirements

For running this, you need to have python3 installed on your system.

Installation

pip install django-rabbitmq-utils==0.0.1

Example

from django_rabbitmq_utils.rabbitmq import send_message_with_retry, consume_messages_from_queue

def send_notification(message):
    send_message_with_retry(message)

def start_message_consumer():
    consume_messages_from_queue('my_queue')

# settings.py
CELERY_QUEUES = getattr(settings, 'CELERY_QUEUES', ())
CELERY_QUEUES += message_routing.routing.get_queues()


# celery.py
from kombu import Connection
from django_rabbitmq_utils.routing import get_exchange

app = Celery('your_project')

@app.task(bind=True)
def process_message(self, body):
    # Connect to RabbitMQ and publish the message with routing key
    with Connection(app.broker_connection()) as connection:
        exchange = get_exchange()
        producer = connection.Producer(serializer='json')
        producer.publish(body, exchange=exchange, routing_key='key1')
# settings.py
import ssl
from django_rabbitmq_utils.rabbitmq_ssl import RABBITMQ_SSL_CONFIG

BROKER_URL = 'amqp://<username>:<password>@<rabbitmq_host>:<rabbitmq_port>/<vhost>'
BROKER_USE_SSL = True
BROKER_SSL_OPTIONS = RABBITMQ_SSL_CONFIG

# seetings.py
COMMANDS = {
    **rabbitmq_integration.register_commands()
}

Project details


Download files

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

Source Distribution

django-rabbitmq-utils-0.0.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

django_rabbitmq_utils-0.0.1-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page