Added API to readme

This commit is contained in:
Ask Solem 2010-06-23 12:10:02 +02:00
parent da3e754594
commit fe5074208d
2 changed files with 35 additions and 11 deletions

View File

@ -6,6 +6,39 @@
**THIS IS A REWRITE OF CARROT**
Proposed API::
from kombu.connection Connection
from kombu.messaging import Exchange, Binding, Consumer, Producer
media_exchange = Exchange("media", "direct", durable=True)
video_binding = Binding("video", exchange=media_exchange, key="video")
# connections/channels
connection = Connection("localhost", "guest", "guest", "/")
channel = connection.channel()
# produce
producer = Producer(channel, exchange=media_exchange, serializer="json")
producer.publish({"name": "/tmp/lolcat1.avi", "size": 1301013})
# consume
consumer = Consumer(channel, video_binding)
consumer.register_callback(process_media)
consumer.consume()
while True:
connection.drain_events()
# consumerset:
video_binding = Binding("video", exchange=media_exchange, key="video")
image_binding = Binding("image", exchange=media_exchange, key="image")
consumer = Consumer(channel, [video_binding, image_binding])
**ORIGINAL CARROT README BELOW**
Introduction
------------

View File

@ -2,8 +2,8 @@
.. code-block:: python
from carrot import Connection, Exchange, Binding
from carrot import Consumer, Producer
from kombu.connection Connection
from kombu.messaging import Exchange, Binding, Consumer, Producer
media_exchange = Exchange("media", "direct", durable=True)
video_binding = Binding("video", exchange=media_exchange, key="video")
@ -30,12 +30,3 @@
image_binding = Binding("image", exchange=media_exchange, key="image")
consumer = Consumer(channel, [video_binding, image_binding])