This article will introduce the difference between control channel and rendezvous channel. And code a simple python application to interpret its process.
Pre-requirement: understand azure relay https://docs.microsoft.com/en-us/azure/azure-relay/relay-what-is-it
The control channel is used to setup a WebSocket to listen the incoming connection. It allows up to 25 concurrent listeners for one hybrid connection. The control channel takes response from step #1 to #5 in following architecture.
When a sender open a new connection. The control channel chose one active listener. The active listener will setup a new WebSocket as rendezvous channel. The messages will be transferred via this rendezvous channel. The rendezvous channel takes response from step #6 to #9 in above architecture.
Below is a simple Python application to realize control channel and rendezvous channel
wss_uri = 'wss://{0}/$hc/{1}?sb-hc-action=listen'.format(service_namespace, entity_path) + '&sb-hc-token=' + urllib.quote(token)
ws = WebSocketApp(wss_uri,
on_message=on_message,
on_error=on_error,
on_close=on_close)
The callback function will use create_connection to create a new WebSocket on this rendezvous url. After finish creating rendezvous channel, the WebSocket will call recv() to receive messages.
def on_message(ws, message):
data = json.loads(message)
url = data["accept"]["address"]
ws = None
try:
ws = create_connection(url)
connected = ws.connected
if connected:
receive_msg = ws.recv()
//process message
….
ws.send(message_process_result)
else:
except Exception, ex:
…
finally:
…
Some times, the callback function will be triggered even sender dose not send any message. It is actually control channel notifications. For example, if the relay server wait long time and can’t get response from listener, it will send a “listener not response immediately” notification to listener side when listener recover.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.