merge helloworld into examples

This commit is contained in:
HVN 2012-12-11 11:35:02 +07:00
parent 920bb3cb73
commit 6f67983182
4 changed files with 41 additions and 36 deletions

View File

@ -4,6 +4,28 @@
Examples 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:
Task Queue Example Task Queue Example

View File

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

View File

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

View File

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