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()