Skip to content

Commit

Permalink
add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed Apr 20, 2017
1 parent 340022b commit 639ab7c
Show file tree
Hide file tree
Showing 9 changed files with 256 additions and 399 deletions.
54 changes: 4 additions & 50 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,57 +41,11 @@ Installation
Usage example
--------------
-------------

.. code-block:: python
import asyncio
from aio_pika import connect
@asyncio.coroutine
def main(loop):
connection = yield from connect("amqp://guest:guest@127.0.0.1/", loop=loop)
queue_name = "test_queue"
routing_key = "test_queue"
# Creating channel
channel = yield from connection.channel()
# Declaring exchange
exchange = yield from channel.declare_exchange('direct', auto_delete=True)
# Declaring queue
queue = yield from channel.declare_queue(queue_name, auto_delete=True)
# Binding queue
yield from queue.bind(exchange, routing_key)
yield from exchange.publish(
Message(
bytes('Hello', 'utf-8'),
content_type='text/plain',
headers={'foo': 'bar'}
),
routing_key
)
# Receiving message
incoming_message = yield from queue.get(timeout=5)
# Confirm message
incoming_message.ack()
yield from queue.unbind(exchange, routing_key)
yield from queue.delete()
yield from connection.close()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
.. literalinclude:: docs/source/examples/main.py
:language: python
:linenos:


See another examples and the tutorial in `documentation`_.
45 changes: 45 additions & 0 deletions docs/source/examples/main.py
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))
54 changes: 3 additions & 51 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,54 +62,8 @@ Installation from git:
Usage example
+++++++++++++

.. code-block:: python
from aio_pika import connect
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))
.. literalinclude:: examples/main.py
:language: python

Development
+++++++++++
Expand Down Expand Up @@ -151,11 +105,9 @@ Thanks for contributing
+++++++++++++++++++++++

* `@mosquito`_ (author)
* `@hellysmile`_ (bug fixes and smart ideas)
* `@adelkhafizova`_ (helps with documentation)
* `@hellysmile`_ (bug fixes and ideas)
* `@alternativehood`_ (bugfixes)

.. _@mosquito: https://github.com/mosquito
.. _@hellysmile: https://github.com/hellysmile
.. _@adelkhafizova: https://github.com/adelkhafizova
.. _@alternativehood: https://github.com/alternativehood
Loading

0 comments on commit 639ab7c

Please sign in to comment.