Sfoglia il codice sorgente

Continuing the routing guide

Ask Solem 15 anni fa
parent
commit
6d8e5d1718
1 ha cambiato i file con 77 aggiunte e 0 eliminazioni
  1. 77 0
      docs/userguide/routing.rst

+ 77 - 0
docs/userguide/routing.rst

@@ -15,6 +15,12 @@ Exchanges, queues and routing keys.
 -----------------------------------
 TODO Mindblowing one-line simple explanation here. TODO
 
+The steps required to send and receive messages are:
+
+    1. Create an exchange
+    2. Create a queue
+    3. Bind the queue to the exchange.
+
 Exchange type
 -------------
 
@@ -77,3 +83,74 @@ It's used for simple admnistration tasks like deleting queues/exchanges,
 purging queues and creating queue entities. In short it's for simple command
 line access to the AMQP API.
 
+You can write commands directly in the arguments to ``camqadm``, or just start
+with no arguments which makes it start in shell-mode::
+
+    $ camqadm
+    -> connecting to amqp://guest@localhost:5672/.
+    -> connected.
+    -->
+
+Here, ``-->`` is the prompt. Type ``help`` for a list of commands, there's
+also autocomplete so you can start typing a command then hit ``tab`` to show a
+list of possible matches.
+
+Now let's create a queue we can send messages to::
+
+    --> exchange.declare testexchange direct
+    ok.
+    --> queue.declare testqueue
+    ok. queue:testqueue messages:0 consumers:0.
+    --> queue.bind testqueue testexchange testkey
+    ok.
+
+
+Messages are sent with a routing key, to an exchange. This is done using
+the ``basic.publish`` command::
+
+    --> basic.publish "This is a message!" testexchange testkey
+    ok.
+
+
+Now that the message is sent we can retrieve it again, we use the
+``basic.get`` command here, which pops a single message off the queue,
+this command is not recommended for production as it implies polling, any
+real application would declare consumers instead::
+
+    --> basic.get testqueue
+    {'body': 'This is a message!',
+     'delivery_info': {'delivery_tag': 1,
+                       'exchange': u'testexchange',
+                       'message_count': 0,
+                       'redelivered': False,
+                       'routing_key': u'testkey'},
+     'properties': {}}
+
+
+AMQP uses acknowledgment to signify a message has been received and processed
+successfully. The message is sent to the next receiver if the client
+connection is closed, and it has not yet been acknowledged.
+
+Note the delivery tag listed in the structure above; Within a connection channel,
+every received message has a unique delivery tag,
+This tag is used to acknowledge the message. Note that
+delivery tags are not unique across connections, so in another client
+the delivery tag ``1`` might point to a different message than in our channel.
+
+You can acknowledge the message we received using ``basic.ack``::
+
+    --> basic.ack 1
+    ok.
+
+
+To clean up after ourselves we should delete the entities we just created::
+
+    --> queue.delete testqueue
+    ok. 0 messages deleted.
+    --> exchange.delete testexchange
+    ok.
+
+
+
+
+