From 6f67983182d6cc9e5fba2e1385db2478d37d9a76 Mon Sep 17 00:00:00 2001 From: HVN Date: Tue, 11 Dec 2012 11:35:02 +0700 Subject: [PATCH] merge helloworld into examples --- docs/userguide/examples.rst | 22 +++++++++++++++++++++ docs/userguide/helloworld.rst | 36 ----------------------------------- examples/hello_consumer.py | 9 +++++++++ examples/hello_publisher.py | 10 ++++++++++ 4 files changed, 41 insertions(+), 36 deletions(-) delete mode 100644 docs/userguide/helloworld.rst create mode 100644 examples/hello_consumer.py create mode 100644 examples/hello_publisher.py diff --git a/docs/userguide/examples.rst b/docs/userguide/examples.rst index 6e9c4e3d..8dc3428c 100644 --- a/docs/userguide/examples.rst +++ b/docs/userguide/examples.rst @@ -4,6 +4,28 @@ Examples ======================== +.. _hello-world-example: + +Hello World Example +================== + +Below example uses +:ref:`guide-simple` +to send helloworld message through +message broker (rabbitmq) and print received message + + +:file:`hello_publisher.py`: + +.. literalinclude:: ../../examples/hello_publisher.py + :language: python + +:file:`hello_consumer.py`: + +.. literalinclude:: ../../examples/hello_consumer.py + :language: python + + .. _task-queue-example: Task Queue Example diff --git a/docs/userguide/helloworld.rst b/docs/userguide/helloworld.rst deleted file mode 100644 index c6632c0c..00000000 --- a/docs/userguide/helloworld.rst +++ /dev/null @@ -1,36 +0,0 @@ -.. _guide-hello-world: - -================== - Hello world uses simple interface -================== - - -Below example uses simple interface to send helloworld message through -message broker (rabbitmq) and print received message - - -:file:`simple_publisher.py`: -.. code-block:: python - from __future__ import with_statement - from kombu import Connection - import datetime - - with Connection('amqp://guest:guest@localhost:5672//') as conn: - simple_queue = conn.SimpleQueue('simple_queue') - message = 'helloword, sent at %s' % datetime.datetime.today() - simple_queue.put(message) - print('Sent: %s' % message) - simple_queue.close() - - -:file:`simple_consumer.py`: -.. code-block:: python - from __future__ import with_statement - from kombu import Connection - - with Connection('amqp://guest:guest@localhost:5672//') as conn: - simple_queue = conn.SimpleQueue('simple_queue') - message = simple_queue.get(block=True, timeout=1) - print("Received: %s" % message.payload) - message.ack() - simple_queue.close() diff --git a/examples/hello_consumer.py b/examples/hello_consumer.py new file mode 100644 index 00000000..03114c98 --- /dev/null +++ b/examples/hello_consumer.py @@ -0,0 +1,9 @@ +from __future__ import with_statement +from kombu import Connection + +with Connection('amqp://guest:guest@localhost:5672//') as conn: + simple_queue = conn.SimpleQueue('simple_queue') + message = simple_queue.get(block=True, timeout=1) + print("Received: %s" % message.payload) + message.ack() + simple_queue.close() diff --git a/examples/hello_publisher.py b/examples/hello_publisher.py new file mode 100644 index 00000000..dd44c038 --- /dev/null +++ b/examples/hello_publisher.py @@ -0,0 +1,10 @@ +from __future__ import with_statement +from kombu import Connection +import datetime + +with Connection('amqp://guest:guest@localhost:5672//') as conn: + simple_queue = conn.SimpleQueue('simple_queue') + message = 'helloword, sent at %s' % datetime.datetime.today() + simple_queue.put(message) + print('Sent: %s' % message) + simple_queue.close()