From 0a5a76ec6a73121c018b36dc165960118888acf9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Wed, 13 Nov 2024 13:50:37 +0100
Subject: [PATCH] docs fix

---
 docs/index.rst                                |  2 +-
 docs/{cluster.rst => reference.rst}           |  4 +-
 .../send_and_receive.rst => tutorials.rst}    | 49 ++++++++++++++++++-
 3 files changed, 51 insertions(+), 4 deletions(-)
 rename docs/{cluster.rst => reference.rst} (92%)
 rename docs/{tutorials/send_and_receive.rst => tutorials.rst} (58%)

diff --git a/docs/index.rst b/docs/index.rst
index 102cf4c..fbdf888 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 2d97ffd..1074dad 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 f8e9724..20a876a 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
-- 
GitLab