diff --git a/docs/index.rst b/docs/index.rst index 102cf4c7a04b1fb519bf612db1361af5054a9390..fbdf8887789969e9e1706c78f9abe3bd9131158d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,7 +7,7 @@ Welcome to CoolAMQP's documentation! whatsnew cluster - tutorials/send_and_receive + tutorials how-to-guide caveats frames diff --git a/docs/cluster.rst b/docs/reference.rst similarity index 92% rename from docs/cluster.rst rename to docs/reference.rst index 2d97ffd1f163f9a31a8c972c38aff0daa384eafc..1074dad88a27df2333aa585ba24a91dd3d6b7685 100644 --- a/docs/cluster.rst +++ b/docs/reference.rst @@ -1,5 +1,5 @@ -CoolAMQP cluster -================ +CoolAMQP cluster reference +========================== .. autoclass:: coolamqp.clustering.Cluster :members: diff --git a/docs/tutorials/send_and_receive.rst b/docs/tutorials.rst similarity index 58% rename from docs/tutorials/send_and_receive.rst rename to docs/tutorials.rst index f8e97241715c09b6b35778672258298ebcec8962..20a876a46fa5e5ace98b209b50a451c3b8095756 100644 --- a/docs/tutorials/send_and_receive.rst +++ b/docs/tutorials.rst @@ -1,5 +1,8 @@ +Tutorials +========= + Send and receive -================ +---------------- In this tutorial we'll learn how to declare a named queue and send a message to it with acknowledgement: @@ -57,3 +60,47 @@ and then disconnect from the server cons.cancel().result() c.shutdown() +Fanout exchanges +---------------- + +Now let's try to do a fanout exchange: + + +.. code-block:: python + + from coolamqp.cluster import Cluster + from coolamqp.objects import NodeDefinition, Exchange + + nd = NodeDefinition('amqp://127.0.0.1:5672/vhost', user='test', password='test', heartbeat=30) + c = Cluster(nd) + c.start() + xchg = Exchange('my-exchange', type='fanout') + +Now let's make two queues that will bind to this queue: + + +.. code-block:: python + + from coolamqp.objects import Queue + + q1 = Queue('my-queue-1', exchange=xchg) + q2 = Queue('my-queue-2', exchange=xchg) + + def handle_message(msg): + print(msg.body.tobytes().encode('utf-8')) + msg.ack() + + c.consume(q1, on_message=handle_message, no_ack=False) + c.consume(q2, on_message=handle_message, no_ack=False) + +Note how you did not have to call :meth:`coolamqp.cluster.Cluster.declare`. Consume will declare constructs of arbitrary +complexity, if they can be derived from the queue objects you passed it. + +And let's try to send something to this exchange: + +.. code-block:: python + + from coolamqp.objects import Message + c.publish(Message(b'my bag of bytes'), exchange=xchg, confirm=True).result() + +And voila, we're done here! \ No newline at end of file