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 787b7dc65 PROTON-2676: [Python] make server examples use ANONYMOUS-RELAY correctly 787b7dc65 is described below commit 787b7dc65fb17efc596d9269706a599e858fc54b Author: Andrew Stitcher <astitc...@apache.org> AuthorDate: Wed Jan 4 18:05:38 2023 -0500 PROTON-2676: [Python] make server examples use ANONYMOUS-RELAY correctly Especially make server.py which actually requires ANONYMOUS-RELAY to work bail if it connects to a broker that doesn't support it - this will avoid an annoying gotcha when running the python examples. Also make server_tx.py correctly check for broker ANONYMOUS-RELAY support. --- python/examples/server.py | 12 +++++++++--- python/examples/server_tx.py | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/python/examples/server.py b/python/examples/server.py index aad550462..3ecd6063b 100755 --- a/python/examples/server.py +++ b/python/examples/server.py @@ -33,9 +33,15 @@ class Server(MessagingHandler): def on_start(self, event): print("Listening on", self.url) self.container = event.container - self.conn = event.container.connect(self.url) - self.receiver = event.container.create_receiver(self.conn, self.address) - self.server = self.container.create_sender(self.conn, None) + self.conn = event.container.connect(self.url, desired_capabilities=["ANONYMOUS-RELAY"]) + + def on_connection_opened(self, event): + if event.connection.remote_offered_capabilities and 'ANONYMOUS-RELAY' in event.connection.remote_offered_capabilities: + 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() def on_message(self, event): print("Received", event.message) diff --git a/python/examples/server_tx.py b/python/examples/server_tx.py index 7a2b9f2f7..4f70cade2 100755 --- a/python/examples/server_tx.py +++ b/python/examples/server_tx.py @@ -50,7 +50,7 @@ class TxServer(MessagingHandler): def on_start(self, event): self.container = event.container - self.conn = event.container.connect(self.host, reconnect=False) + self.conn = event.container.connect(self.host, reconnect=False, desired_capabilities=["ANONYMOUS-RELAY"]) self.receiver = event.container.create_receiver(self.conn, self.address) self.senders = {} self.relay = None @@ -67,7 +67,7 @@ class TxServer(MessagingHandler): correlation_id=event.message.correlation_id) self.container.declare_transaction(self.conn, handler=TxRequest(response, sender, event.delivery)) - def on_connection_open(self, event): + def on_connection_opened(self, event): if event.connection.remote_offered_capabilities and 'ANONYMOUS-RELAY' in event.connection.remote_offered_capabilities: self.relay = self.container.create_sender(self.conn, None) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org