Last active
April 11, 2018 16:19
-
-
Save askabelin/6794590630590255283b979c2677c172 to your computer and use it in GitHub Desktop.
Multiple readers work synchronously
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
import asyncio | |
import aio_pika | |
async def read(reader_id): | |
connection = await aio_pika.connect_robust(**RMQ_CONFIG) | |
async with connection: | |
channel = await connection.channel() | |
queue = await channel.declare_queue('test_queue', durable=True) | |
message = await queue.get() | |
# the difference is here | |
async for message in queue: | |
with message.process(): | |
print(reader_id) | |
await asyncio.sleep(1) # emulate async task | |
if __name__ == '__main__': | |
loop = asyncio.get_event_loop() | |
readers = [read(i) for i in range(3)] | |
loop.run_until_complete(asyncio.wait(readers)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment