This article is contributed. See the original author and article here.

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.


Hai_Yue_0-1611302951299.png


 


 


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


 



  1. Below code will create a control 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)


 



  1. Follow is control channel’s on_message callback function. The sender connection on the control channel will contains a url. The url is the rendezvous url need to be established.


 


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.

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.