From 91d60d5c949e56819d0a419040c92dae1efb9e61 Mon Sep 17 00:00:00 2001 From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl> Date: Sat, 28 Jan 2017 23:27:07 +0100 Subject: [PATCH] moar docs --- docs/index.rst | 5 ----- docs/tutorial.md | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index a499442..86ca101 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,8 +1,3 @@ -.. CoolAMQP documentation master file, created by - sphinx-quickstart on Sat Jan 28 16:24:42 2017. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - Welcome to CoolAMQP's documentation! ==================================== diff --git a/docs/tutorial.md b/docs/tutorial.md index 7e3152a..b10c67c 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -25,4 +25,43 @@ cluster = Cluster([node]) cluster.start(wait=True) ``` -_wait=True_ will block until connection is completed. After this, you can use other methods. \ No newline at end of file +_wait=True_ will block until connection is completed. After this, you can use other methods. + +## Publishing and consuming + +Connecting is boring. After we do, we want to do something! Let's try sending a message, and receiving it. To do that, +you must first define a queue, and register a consumer. + +```python +from coolamqp.objects import Queue + +queue = Queue(u'my_queue', auto_delete=True, exclusive=True) + +consumer, consume_confirm = cluster.consume(queue, no_ack=False) +consume_confirm.result() # wait for consuming to start +``` + +This will create an auto-delete and exclusive queue. After than, a consumer will be registered for this queue. +_no_ack=False_ will mean that we have to manually confirm messages. + +You can specify a callback, that will be called with a message if one's received by this consumer. Since +we did not do that, this will go to a generic queue belonging to _Cluster_. + +_consumer_ is a _Consumer_ object. This allows us to do some things with the consumer (such as setting QoS), +but most importantly it allows us to cancel it later. _consume_confirm_ is a _Future_, that will succeed +when AMQP _basic.consume-ok_ is received. + +To send a message we need to construct it first, and later publish: + +```python +from coolamqp.objects import Message + +msg = Message(b'hello world', properties=Message.Properties()) +cluster.publish(msg, routing_key=u'my_queue') +``` + +This creates a message with no properties, and sends it through default (direct) exchange to our queue. +Note that CoolAMQP simply considers your messages to be bags of bytes + properties. It will not modify them, +nor decode, and will always expect and return bytes. + +To actually get our message ... \ No newline at end of file -- GitLab