Skip to content

Commit

Permalink
fix readme.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Apr 20, 2017
1 parent 639ab7c commit f6ad7a9
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,53 @@ Installation
Usage example
-------------

.. literalinclude:: docs/source/examples/main.py
:language: python
:linenos:
.. code-block:: python
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))
See another examples and the tutorial in `documentation`_.

0 comments on commit f6ad7a9

Please sign in to comment.