Expose dramatiq headers via an options message through a thread-local variable in middleware.
Project description
🦅 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
[!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.
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
dramatiq_header-0.1.2.tar.gz
(3.1 kB
view hashes)
Built Distribution
Close
Hashes for dramatiq_header-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93c783d3fa69dc92f78192f8fdf8aed9d824890b4b08288e4ddf15bb5bfeb7a2 |
|
MD5 | f46f207de35f4e4c2ba31e9d79cded9c |
|
BLAKE2b-256 | 9631bce276734999b7de09c3d3d97bb2815188dd717ccf9ecb74bfc99f09963c |