RabbitMQ Decorator
- Work in progress
Easily send and receive messages to and from RabbitMQ message broker.
Installation
pip install rabbitmq-decorator
Usage
Optional:
export RABBITMQ_HOST=localhost
export RABBITMQ_PORT=5672
export RABBITMQ_USERNAME=username
export RABBITMQ_PASSWORD=password
Example:
import asyncio
from typing import Dict, Any
from rabbitmq_decorator import RabbitMQHandler, RabbitMQConsumer, RabbitMQProducer, RabbitMQMessage, Exchange
event_loop = asyncio.get_event_loop()
# If environment variables was set
rabbit_handler = RabbitMQHandler(event_loop=event_loop)
# Or if environment variables wasn't set
rabbit_handler = RabbitMQHandler(
event_loop=event_loop,
rabbitmq_host="localhost",
rabbitmq_port=5672,
rabbitmq_username="username",
rabbitmq_password="password"
)
@rabbit_handler
class SomeClass:
EXCHANGE = Exchange("test_exchange", durable=True)
_producer: RabbitMQProducer = rabbit_handler.get_new_producer(EXCHANGE)
def some_unrelated_function(self):
pass
@RabbitMQConsumer(EXCHANGE)
async def consumer_1(self, body: Dict[str, Any]):
print("I'm getting all the messages on test_exchange")
self._producer.publish(RabbitMQMessage(routing_key="response.consumer1", body={"status": "Success"}))
@RabbitMQConsumer(EXCHANGE, route="*.*.*")
async def consumer_2(self, body: Dict[str, Any]):
print("I'm getting only the messages on test_exchange with *.*.* as routing-key ")
response_exchange = Exchange("response_exchanges", durable=True)
self._producer.publish(
exchange=response_exchange,
message=RabbitMQMessage(routing_key="response.consumer2", body={"status": "Success"})
)
# ================ main ================
async def main():
"""do something"""
if __name__ == '__main__':
some_class = SomeClass()
rabbit_handler.start(some_class)
event_loop.run_until_complete(main())
rabbit_handler.stop_consume(some_class)
Metadata
Release files for rabbitmq-decorator 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rabbitmq-decorator-0.0.1.tar.gz | 11.4 kB | Without provenance | Details for rabbitmq-decorator-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rabbitmq_decorator-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for rabbitmq_decorator-0.0.1-py3-none-any.whl |
Total release size: 25.3 kB
Release files / rabbitmq-decorator-0.0.1.tar.gz
| Download URL | rabbitmq-decorator-0.0.1.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac1acfc1484e27366b3d79c31b674caaefda66e209eb4d26c43b10795eb7fda3
|
|
BLAKE2b-256 checksum How to use checksums |
3f09871e0d5b1c8eb792b2a70b6c70dae3eb3670dd0f3e7293dd02f472a6479f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / rabbitmq_decorator-0.0.1-py3-none-any.whl
| Download URL | rabbitmq_decorator-0.0.1-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b23a9ea03d2cd650dad5463a8d52667fc9a960694e5e23ea03d750e79f23010
|
|
BLAKE2b-256 checksum How to use checksums |
5c18ed28107e05894d8a1ae125c2f0468a9f7119002417aa5fe3501b995bc957
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for rabbitmq-decorator 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.