Skip to content
Snippets Groups Projects
Commit 0a5a76ec authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

docs fix

parent 952fdf1a
No related branches found
No related tags found
No related merge requests found
Pipeline #63902 passed with stages
in 2 minutes and 30 seconds
...@@ -7,7 +7,7 @@ Welcome to CoolAMQP's documentation! ...@@ -7,7 +7,7 @@ Welcome to CoolAMQP's documentation!
whatsnew whatsnew
cluster cluster
tutorials/send_and_receive tutorials
how-to-guide how-to-guide
caveats caveats
frames frames
......
CoolAMQP cluster CoolAMQP cluster reference
================ ==========================
.. autoclass:: coolamqp.clustering.Cluster .. autoclass:: coolamqp.clustering.Cluster
:members: :members:
......
Tutorials
=========
Send and receive Send and receive
================ ----------------
In this tutorial we'll learn how to declare a named queue and send a message to it with acknowledgement: 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 ...@@ -57,3 +60,47 @@ and then disconnect from the server
cons.cancel().result() cons.cancel().result()
c.shutdown() 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment