A simple RabbitMQ/Pika wrapper for publishing and consuming events
Project description
tchu
A lightweight Python wrapper around Pika/RabbitMQ for easy event publishing and consuming.
Installation
chu @ git+https://github.com/Sigularusrex/tchu@main
make a management command like this:
from tchu.consumer import ThreadedConsumer
from django.core.management.base import BaseCommand
from gc_api.subscribers.tchu_callback import tchu_callback
from settings import RABBITMQ_BROKER_URL
class Command(BaseCommand):
help = "Launches Listener for Service A events: RabbitMQ"
def handle(self, *args, **options):
consumer = ThreadedConsumer(
amqp_url=RABBITMQ_BROKER_URL,
exchange="exchange-name",
exchange_type="topic",
threads=5,
routing_keys=["event_topic.*"],
callback=tchu_callback,
)
# Start consuming messages
consumer.run()
Provide it with a callback function (Mine just blindly publishes to Celery :smile: ) import json
import celery_pubsub
def tchu_callback(ch, method, properties, body):
try:
print("External message received in Service A")
data = json.loads(body)
celery_pubsub.publish(method.routing_key, data)
print("Message published in Service A")
except Exception as e:
print(f"Error publishing message: {e}")
...and you're good to go.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tchu-0.1.0.tar.gz.
File metadata
- Download URL: tchu-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.11.3 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1467b5aa60ca4e424c77e9e00689d47be9374dfff48a348e3330411220407a5
|
|
| MD5 |
dba766938e2274e0373e47ab939232db
|
|
| BLAKE2b-256 |
2a9bae46eadae84cf8860a575d525e40646e4a1b2820d928468aefa07c493823
|
File details
Details for the file tchu-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tchu-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.11.3 Darwin/24.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc0298c9caab7a8021e255a756d13fd18055377cadf30ca179bccc51479a4a30
|
|
| MD5 |
ded8f95f3485ba918759ef8ecf54c6d5
|
|
| BLAKE2b-256 |
bbb568571d9fa56324f7336878fbdaffca24e7a7de3f9447260067e5fb8e866e
|