From b6d679fe34d8e5346dd1e00db5ce7613324f074d Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Wed, 1 Dec 2010 12:28:10 +0100 Subject: [PATCH] Added SimpleQueue examples: examples/simple_receive.py, simple_send.py --- .../{demo_receive.py => complete_receive.py} | 0 examples/{demo_send.py => complete_send.py} | 0 examples/simple_receive.py | 24 +++++++++++++++++ examples/simple_send.py | 27 +++++++++++++++++++ 4 files changed, 51 insertions(+) rename examples/{demo_receive.py => complete_receive.py} (100%) rename examples/{demo_send.py => complete_send.py} (100%) create mode 100644 examples/simple_receive.py create mode 100644 examples/simple_send.py diff --git a/examples/demo_receive.py b/examples/complete_receive.py similarity index 100% rename from examples/demo_receive.py rename to examples/complete_receive.py diff --git a/examples/demo_send.py b/examples/complete_send.py similarity index 100% rename from examples/demo_send.py rename to examples/complete_send.py diff --git a/examples/simple_receive.py b/examples/simple_receive.py new file mode 100644 index 00000000..276d30cf --- /dev/null +++ b/examples/simple_receive.py @@ -0,0 +1,24 @@ +""" +Example receiving a message using the SimpleQueue interface. +""" + +from kombu import BrokerConnection + +#: Create connection +#: If hostname, userid, password and virtual_host is not specified +#: the values below are the default, but listed here so it can +#: be easily changed. +connection = BrokerConnection(hostname="localhost", + userid="guest", + password="guest", + virtual_host="/") + + +#: SimpleQueue mimics the interface of the Python Queue module. +#: First argument can either be a queue name or a kombu.Queue object. +#: If a name, then the queue will be declared with the name as the queue +#: name, exchange name and routing key. +queue = connection.SimpleQueue("kombu_demo") +message = queue.get(block=True, timeout=10) +message.ack() +print(message.payload) diff --git a/examples/simple_send.py b/examples/simple_send.py new file mode 100644 index 00000000..11a5e330 --- /dev/null +++ b/examples/simple_send.py @@ -0,0 +1,27 @@ +""" + +Example that sends a single message and exits using the simple interface. + +You can use `simple_receive.py` (or `complete_receive.py`) to receive the +message sent. + +""" + +from kombu import BrokerConnection + +#: Create connection +#: If hostname, userid, password and virtual_host is not specified +#: the values below are the default, but listed here so it can +#: be easily changed. +connection = BrokerConnection(hostname="localhost", + userid="guest", + password="guest", + virtual_host="/") + + +#: SimpleQueue mimics the interface of the Python Queue module. +#: First argument can either be a queue name or a kombu.Queue object. +#: If a name, then the queue will be declared with the name as the queue +#: name, exchange name and routing key. +queue = connection.SimpleQueue("kombu_demo") +queue.put({"hello": "world"}, serializer="json", compression="zlib")