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