-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
256 additions
and
399 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import asyncio | ||
from aio_pika import connect, Message | ||
|
||
|
||
async def main(loop): | ||
connection = await connect("amqp://guest:guest@127.0.0.1/", loop=loop) | ||
|
||
queue_name = "test_queue" | ||
routing_key = "test_queue" | ||
|
||
# Creating channel | ||
channel = await connection.channel() | ||
|
||
# Declaring exchange | ||
exchange = await channel.declare_exchange('direct', auto_delete=True) | ||
|
||
# Declaring queue | ||
queue = await channel.declare_queue(queue_name, auto_delete=True) | ||
|
||
# Binding queue | ||
await queue.bind(exchange, routing_key) | ||
|
||
await exchange.publish( | ||
Message( | ||
bytes('Hello', 'utf-8'), | ||
content_type='text/plain', | ||
headers={'foo': 'bar'} | ||
), | ||
routing_key | ||
) | ||
|
||
# Receiving message | ||
incoming_message = await queue.get(timeout=5) | ||
|
||
# Confirm message | ||
incoming_message.ack() | ||
|
||
await queue.unbind(exchange, routing_key) | ||
await queue.delete() | ||
await connection.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(main(loop)) |
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
Oops, something went wrong.