This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/main by this push:
new da94d935f PROTON-2676: Make server example behave better if no relay
da94d935f is described below
commit da94d935f644320d72da69cb0dfe3064d70dc95b
Author: Andrew Stitcher <[email protected]>
AuthorDate: Wed Feb 22 18:07:45 2023 +0000
PROTON-2676: Make server example behave better if no relay
We'll now close the connection with an error and exit with a non-zero
exit code if ANONYMOUS-RELAY isn't offered by the connected broker.
---
python/examples/server.py | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/python/examples/server.py b/python/examples/server.py
index 3ecd6063b..403ceec00 100755
--- a/python/examples/server.py
+++ b/python/examples/server.py
@@ -19,10 +19,12 @@
#
import optparse
-from proton import Message, Url
+import sys
+from proton import Message, Url, Condition
from proton.handlers import MessagingHandler
from proton.reactor import Container
+exit_status = 0
class Server(MessagingHandler):
def __init__(self, url, address):
@@ -40,8 +42,12 @@ class Server(MessagingHandler):
self.receiver = event.container.create_receiver(self.conn,
self.address)
self.server = self.container.create_sender(self.conn, None)
else:
- print("Server needs a broker which supports ANONYMOUS-RELAY")
- event.connection.close()
+ global exit_status
+ print("Server needs a broker which supports ANONYMOUS-RELAY",
file=sys.stderr)
+ exit_status = 1
+ c= event.connection
+ c.condition = Condition('amqp:not-implemented',
description="ANONYMOUS-RELAY required")
+ c.close()
def on_message(self, event):
print("Received", event.message)
@@ -60,3 +66,5 @@ try:
Container(Server(url, url.path)).run()
except KeyboardInterrupt:
pass
+
+sys.exit(exit_status)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]