<h1 align="center">
🦅 Dramatiq Header Middleware for RabbitMQ
</h1>
# 🛠 Installation
```sh
pip install dramatiq-header
```
# ⬆️ Upgrade version
```sh
pip install dramatiq-header --upgrade
```
# ✏️ Usage
## Worker code:
```py
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:
```py
rabbitmq_broker.add_middleware(HeadersMessage('x-test-header'))
```
## Sender example
```py
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](https://github.com/guedesfelipe/dramatiq-header/assets/25853920/bc5bd345-b694-4553-8daa-65172ac6b384)
> [!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.
---
<p align="center">
<a href="https://ko-fi.com/guedesfelipe" target="_blank">
<img src="https://user-images.githubusercontent.com/25853920/175832199-6c75d866-31b8-4209-bd1a-db116a6dd032.png" width=300 />
</a>
</p>
Raw data
{
"_id": null,
"home_page": "https://github.com/guedesfelipe/dramatiq-header",
"name": "dramatiq-header",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "dramatiq,header,dramatiq header,rabbitmq",
"author": "Felipe Guedes",
"author_email": "contatofelipeguedes@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/6b/57/1f35495e4f1a1828c99ff03470d5fbf4dd69f36a4cd73691d0bcbb75bbef/dramatiq_header-0.1.2.tar.gz",
"platform": null,
"description": "<h1 align=\"center\">\n \ud83e\udd85 Dramatiq Header Middleware for RabbitMQ\n</h1>\n\n\n# \ud83d\udee0 Installation\n\n```sh\npip install dramatiq-header\n```\n\n# \u2b06\ufe0f Upgrade version\n\n```sh\npip install dramatiq-header --upgrade\n```\n\n# \u270f\ufe0f Usage\n\n\n## Worker code:\n\n```py\nimport dramatiq\nfrom dramatiq.brokers.rabbitmq import RabbitmqBroker\nfrom dramatiq_header import HeadersMessage # Import Middleware\n\n\nrabbitmq_broker = RabbitmqBroker()\ndramatiq.set_broker(rabbitmq_broker)\n\n\nrabbitmq_broker.add_middleware(HeadersMessage()) # Add Middleware\n\n\n@dramatiq.actor(queue_name='example')\ndef my_task(message):\n print(f'Message Received: {message}')\n print(HeadersMessage.get_headers()) # Get headers\n\n```\n\n> [!TIP]\n> You can add middleware specifically to monitor a header key. For example:\n```py\nrabbitmq_broker.add_middleware(HeadersMessage('x-test-header'))\n```\n\n\n## Sender example\n\n```py\nimport dramatiq\nfrom dramatiq import Message\nfrom dramatiq.brokers.rabbitmq import RabbitmqBroker\n\n\nrabbitmq_broker = RabbitmqBroker()\ndramatiq.set_broker(rabbitmq_broker)\n\n\ndef send_message(msg: str):\n message = Message(\n queue_name='example',\n actor_name='my_task',\n args=(msg, ),\n kwargs={},\n options={'x-test-header': 'test-header'}, # Send your entire header here\n )\n rabbitmq_broker.enqueue(message)\n\n\nif __name__ == '__main__':\n send_message('test message')\n```\n\n## Output\n![image](https://github.com/guedesfelipe/dramatiq-header/assets/25853920/bc5bd345-b694-4553-8daa-65172ac6b384)\n\n\n> [!IMPORTANT] \n> 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.\n\n\n---\n\n<p align=\"center\">\n <a href=\"https://ko-fi.com/guedesfelipe\" target=\"_blank\">\n <img src=\"https://user-images.githubusercontent.com/25853920/175832199-6c75d866-31b8-4209-bd1a-db116a6dd032.png\" width=300 />\n </a>\n</p>\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Expose dramatiq headers via an options message through a thread-local variable in middleware.",
"version": "0.1.2",
"project_urls": {
"Documentation": "https://github.com/guedesfelipe/dramatiq-header",
"Homepage": "https://github.com/guedesfelipe/dramatiq-header",
"Repository": "https://github.com/guedesfelipe/dramatiq-header"
},
"split_keywords": [
"dramatiq",
"header",
"dramatiq header",
"rabbitmq"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9631bce276734999b7de09c3d3d97bb2815188dd717ccf9ecb74bfc99f09963c",
"md5": "f46f207de35f4e4c2ba31e9d79cded9c",
"sha256": "93c783d3fa69dc92f78192f8fdf8aed9d824890b4b08288e4ddf15bb5bfeb7a2"
},
"downloads": -1,
"filename": "dramatiq_header-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f46f207de35f4e4c2ba31e9d79cded9c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 3398,
"upload_time": "2024-03-04T00:48:20",
"upload_time_iso_8601": "2024-03-04T00:48:20.009428Z",
"url": "https://files.pythonhosted.org/packages/96/31/bce276734999b7de09c3d3d97bb2815188dd717ccf9ecb74bfc99f09963c/dramatiq_header-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "6b571f35495e4f1a1828c99ff03470d5fbf4dd69f36a4cd73691d0bcbb75bbef",
"md5": "a1d74213fba7b2bc6415234b40ae7fac",
"sha256": "babe9b6ba526f4f85c4666680d85287106b7fd07d127f9699869f38867f52bbe"
},
"downloads": -1,
"filename": "dramatiq_header-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "a1d74213fba7b2bc6415234b40ae7fac",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 3076,
"upload_time": "2024-03-04T00:48:21",
"upload_time_iso_8601": "2024-03-04T00:48:21.589037Z",
"url": "https://files.pythonhosted.org/packages/6b/57/1f35495e4f1a1828c99ff03470d5fbf4dd69f36a4cd73691d0bcbb75bbef/dramatiq_header-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-04 00:48:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "guedesfelipe",
"github_project": "dramatiq-header",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "dramatiq-header"
}