Skip to main content

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

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.


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

dramatiq_header-0.1.2.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dramatiq_header-0.1.2-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file dramatiq_header-0.1.2.tar.gz.

File metadata

  • Download URL: dramatiq_header-0.1.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for dramatiq_header-0.1.2.tar.gz
Algorithm Hash digest
SHA256 babe9b6ba526f4f85c4666680d85287106b7fd07d127f9699869f38867f52bbe
MD5 a1d74213fba7b2bc6415234b40ae7fac
BLAKE2b-256 6b571f35495e4f1a1828c99ff03470d5fbf4dd69f36a4cd73691d0bcbb75bbef

See more details on using hashes here.

File details

Details for the file dramatiq_header-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for dramatiq_header-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 93c783d3fa69dc92f78192f8fdf8aed9d824890b4b08288e4ddf15bb5bfeb7a2
MD5 f46f207de35f4e4c2ba31e9d79cded9c
BLAKE2b-256 9631bce276734999b7de09c3d3d97bb2815188dd717ccf9ecb74bfc99f09963c

See more details on using hashes here.

Supported by

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