Skip to main content

🦅 Dramatiq Header Middleware for RabbitMQ

🛠 Installation

pip install dramatiq-header

⬆️ Upgrade version

pip install dramatiq-header --upgrade

✏️ Usage

Worker code:

import dramatiq
from dramatiq.brokers.rabbitmq import RabbitmqBroker
from dramatiq_header import HeadersMessage # Import Middleware


rabbitmq_broker = RabbitmqBroker()
dramatiq.set_broker(rabbitmq_broker)


rabbitmq_broker.add_middleware(HeadersMessage()) # Add Middleware


@dramatiq.actor(queue_name='example')
def my_task(message):
    print(f'Message Received: {message}')
    print(HeadersMessage.get_headers()) # Get headers

[!TIP] You can add middleware specifically to monitor a header key. For example:

rabbitmq_broker.add_middleware(HeadersMessage('x-test-header'))

Sender example

import dramatiq
from dramatiq import Message
from dramatiq.brokers.rabbitmq import RabbitmqBroker


rabbitmq_broker = RabbitmqBroker()
dramatiq.set_broker(rabbitmq_broker)


def send_message(msg: str):
    message = Message(
        queue_name='example',
        actor_name='my_task',
        args=(msg, ),
        kwargs={},
        options={'x-test-header': 'test-header'}, # Send your entire header here
    )
    rabbitmq_broker.enqueue(message)


if __name__ == '__main__':
    send_message('test message')

Output

image

[!IMPORTANT]
This library does NOT transmit the header using the RabbitMQ header property; rather, it sends the header as metadata within the message that Dramatiq already dispatches.


Metadata

Release files for dramatiq-header 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dramatiq-header 0.1.2
File Size Uploaded
dramatiq_header-0.1.2.tar.gz 3.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dramatiq-header 0.1.2
File Interpreter ABI Platform
dramatiq_header-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / dramatiq_header-0.1.2.tar.gz

Download URL dramatiq_header-0.1.2.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
babe9b6ba526f4f85c4666680d85287106b7fd07d127f9699869f38867f52bbe
BLAKE2b-256 checksum
How to use checksums
6b571f35495e4f1a1828c99ff03470d5fbf4dd69f36a4cd73691d0bcbb75bbef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release files / dramatiq_header-0.1.2-py3-none-any.whl

Download URL dramatiq_header-0.1.2-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93c783d3fa69dc92f78192f8fdf8aed9d824890b4b08288e4ddf15bb5bfeb7a2
BLAKE2b-256 checksum
How to use checksums
9631bce276734999b7de09c3d3d97bb2815188dd717ccf9ecb74bfc99f09963c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page