Giter VIP home page Giter VIP logo

chu's Introduction

chu

I got sick of needing a Pika listener on every app, so I made a small library called Chu, that does it for you. I'll update the docs soon, but essentially you can install Chu:

chu @ git+https://github.com/Sigularusrex/chu@main

make a management command like this:

from chu.consumer import ThreadedConsumer
from django.core.management.base import BaseCommand

from gc_api.subscribers.chu_callback import chu_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=chu_callback,
		)
		# Start consuming messages
		consumer.run()

Provide it with a callback function (Mine just blindly publishes to Celery ๐Ÿ˜„ ) import json

import celery_pubsub


def chu_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.

chu's People

Contributors

sigularusrex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.