Created
July 10, 2015 22:53
-
-
Save kflavin/69002e58d579e90f1f41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@asyncio.coroutine | |
def do_work(envelope, body): | |
yield from asyncio.sleep(body) | |
@asyncio.coroutine | |
def callback(body, envelope, properties): | |
loop = asyncio.get_event_loop() | |
loop.create_task(do_work(envelope, body)) | |
@asyncio.coroutine | |
def receive_log(): | |
try: | |
transport, protocol = yield from aioamqp.connect('host', 5672, login="login", password="password") | |
except: | |
print("closed connections") | |
return | |
channel = yield from protocol.channel() | |
yield from channel.exchange(exchange_name, 'topic', auto_delete=True, passive=False, durable=False) | |
yield from asyncio.wait_for(channel.queue(queue_name, durable=False), timeout=10) | |
yield from asyncio.wait_for(channel.queue_bind(exchange_name="exchange_name", | |
queue_name="queue_name", | |
routing_key="bindingkey"), timeout=10) | |
print(' [*] Waiting for logs. To exit press CTRL+C') | |
message = yield from channel.basic_consume(queue_name, callback=callback) | |
loop = asyncio.get_event_loop() | |
loop.create_task(receive_log()) | |
loop.run_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment