Skip to content

Commit

Permalink
Adds async_consume example
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Feb 3, 2014
1 parent 4bb7cae commit f87256e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/experimental/async_consume.py
@@ -0,0 +1,29 @@
#!/usr/bin/env python

from kombu import Connection, Exchange, Queue, Producer, Consumer
from kombu.async import Hub
from threading import Event

hub = Hub()
exchange = Exchange('asynt')
queue = Queue('asynt', exchange, 'asynt')

def send_message(conn):
producer = Producer(conn)
producer.publish('hello world', exchange=exchange, routing_key='asynt')
print('MESSAGE SENT')


def on_message(message):
print('RECEIVED: %r' % (message.body, ))
message.ack()
hub.stop() # <-- exit after one message


if __name__ == '__main__':
conn = Connection('amqp://')
conn.register_with_event_loop(hub)

with Consumer(conn, [queue], on_message=on_message):
send_message(conn)
hub.run_forever()

0 comments on commit f87256e

Please sign in to comment.