A simple implementation of STOMP with Django
Project description
Django Stomp
A simple implementation of STOMP with Django.
In theory it can work with any broker which supports STOMP with none or minor adjustments.
Installation
pip install django_stomp
Add django_stomp
in your INSTALLED_APPS
and so be it.
Configuration process
Not yet fully available, but feel free to see our tests to get insights.
Consumer
First you must create a function which receives an parameter of type django_stomp.services.consumer.Payload
. Let's suppose the module app.sample
with the following content:
import logging
from django_stomp.services.consumer import Payload
logger = logging.getLogger(__name__)
def my_honest_logic(payload: Payload) -> None:
logger.info("Yeah, I received a payload from django-stomp!")
my_payload = payload.body
my_header = payload.headers
if my_payload.get("my-dict-key"):
payload.ack()
else:
logger.info("To DLQ!")
payload.nack()
Now you must provide broker connection details filling out the following parameters at least:
- STOMP_SERVER_HOST
- STOMP_SERVER_PORT
- STOMP_USE_SSL
And just create the job issuing the following command:
python manage.py pubsub "/queue/your-stuff" app.sample.my_honest_logic
That's it ✌️
Tests
In order to execute tests for ActiveMQ, execute the following:
docker-compose up -d broker-activemq
Or for RabbitMQ:
docker-compose up -d broker-rabbitmq
Then at last:
pipenv run tox
Known limitations
- Currently, we assume that all dead lettered messages are sent to a queue with the same name as its original destination but prefixed with
DLQ.
, i.e., if your queue is/queue/some-queue
, the dead letter destination is asssumed to be/queue/DLQ.some-queue
. - Be cautious with the heartbeat functionality! If your consumer is slow, it could prevent the client to receive and process any
heart-beat
frame sent by the server, causing the client to terminate the connection due to a false positive heartbeat timeout.
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
Built Distribution
Hashes for django_stomp-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de8ca7bacc9cc90b1f83427db190c824210b79a37f9a97701657256c30eb4db0 |
|
MD5 | 581c74b7c73d9cd6cbfdb32f816e7450 |
|
BLAKE2b-256 | 53154e9a31fbf4c4f7f5e8ab16d0a0cfe687d26b0c6fa8b16cc3f9b1ca934522 |