summaryrefslogtreecommitdiff
path: root/python/examples/api
diff options
context:
space:
mode:
Diffstat (limited to 'python/examples/api')
-rwxr-xr-xpython/examples/api/drain5
-rwxr-xr-xpython/examples/api/server38
-rwxr-xr-xpython/examples/api/spout12
3 files changed, 27 insertions, 28 deletions
diff --git a/python/examples/api/drain b/python/examples/api/drain
index f2d7a50058..c244cbc09c 100755
--- a/python/examples/api/drain
+++ b/python/examples/api/drain
@@ -93,9 +93,8 @@ try:
ssn.acknowledge()
except Empty:
break
- except ReceiveError, e:
- print e
- break
+except ReceiveError, e:
+ print e
except KeyboardInterrupt:
pass
diff --git a/python/examples/api/server b/python/examples/api/server
index a9cd8579e3..d7cd53de4b 100755
--- a/python/examples/api/server
+++ b/python/examples/api/server
@@ -51,15 +51,12 @@ else:
parser.error("address is required")
# XXX: should make URL default the port for us
-conn = Connection.open(url.host, url.port or AMQP_PORT,
- username=url.user,
- password=url.password,
- reconnect=opts.reconnect,
- reconnect_delay=opts.reconnect_delay,
- reconnect_limit=opts.reconnect_limit)
-ssn = conn.session()
-rcv = ssn.receiver(addr)
-
+conn = Connection(url.host, url.port or AMQP_PORT,
+ username=url.user,
+ password=url.password,
+ reconnect=opts.reconnect,
+ reconnect_delay=opts.reconnect_delay,
+ reconnect_limit=opts.reconnect_limit)
def dispatch(msg):
msg_type = msg.properties.get("type")
if msg_type == "shell":
@@ -77,21 +74,26 @@ def dispatch(msg):
result = Message("unrecognized message type: %s" % msg_type)
return result
-while True:
- try:
+try:
+ conn.connect()
+ ssn = conn.session()
+ rcv = ssn.receiver(addr)
+
+ while True:
msg = rcv.fetch()
response = dispatch(msg)
- snd = ssn.sender(msg.reply_to)
+ snd = None
try:
+ snd = ssn.sender(msg.reply_to)
snd.send(response)
except SendError, e:
print e
- snd.close()
+ if snd is not None:
+ snd.close()
ssn.acknowledge()
- except Empty:
- break
- except ReceiveError, e:
- print e
- break
+except ReceiveError, e:
+ print e
+except KeyboardInterrupt:
+ pass
conn.close()
diff --git a/python/examples/api/spout b/python/examples/api/spout
index 97cb540c21..5479b66211 100755
--- a/python/examples/api/spout
+++ b/python/examples/api/spout
@@ -113,13 +113,11 @@ try:
name, val = nameval(p)
msg.properties[name] = val
- try:
- snd.send(msg)
- count += 1
- print msg
- except SendError, e:
- print e
- break
+ snd.send(msg)
+ count += 1
+ print msg
+except SendError, e:
+ print e
except KeyboardInterrupt:
pass