diff options
Diffstat (limited to 'examples/simple_receive.py')
-rw-r--r-- | examples/simple_receive.py | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/examples/simple_receive.py b/examples/simple_receive.py index 6be741c4..9d53aa35 100644 --- a/examples/simple_receive.py +++ b/examples/simple_receive.py @@ -2,27 +2,27 @@ Example receiving a message using the SimpleQueue interface. """ +from __future__ import with_statement + 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="/") - +with BrokerConnection("amqp://guest:guest@localhost:5672//") as conn: -#: 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) + #: 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. + with conn.SimpleQueue("kombu_demo") as queue: + message = queue.get(block=True, timeout=10) + message.ack() + print(message.payload) -#: Always remember to close connections and channels. -queue.close() -connection.close() +#### +#: If you don't use the with statement then you must aways +# remember to close objects after use: +# queue.close() +# connection.close() |