carrot
carrot copied to clipboard
New API
The current Consumer
/Publisher
classes hides the channels, I think we should rethink the API altogether.
Braindump:
from carrot import Connection, Consumer, Producer
connection = Connection(host="localhost", user="guest", "password="guest", vhost="/")
channel = connection.Channel()
consumer = Consumer(channel, queue="celery", exchange="celery", routing_key="celery")
consumer.register_callback(process_task)
while True:
connection.drain_events()
# or channel.drain_events() will only receive events on that channel.
producer = Producer(channel, exchange="celery")
producer.publish({"task": "celery.ping", args=[], kwargs={}}, serializer="pickle")
A ConsumerSet is now simply using the same channel with more than one consumer:
channel = connection.Channel()
c1 = Consumer(channel, queue="foo")
c2 = Consumer(channel, queue="bar")
c3 = Consumer(channel, queue="baz")
while True:
connection.drain_events()