Azure Relay - Not able to Consume/Receive events via Azure Hybrid Connection with Node

82 views Asked by At

We are working on integration where we have to consume/receive the events by initiating hybrid connection to Azure relay. we are able to do the successful connection using hyco-ws npm package but we are not receiving any events.

As per hybrid connection protocol, service will send 'accept' notification to the listener to establish new control channel for all subsequent interactions.

From where can we trigger 'accept' notification so listener can receive events from the Azure relay?

We are following Azure Relay Hybrid Connections WebSocket NodeJs to setup the listener.

enter image description here

Are we on right direction to receive the events via hybrid connection?

Any help in the right direction would be greatly appreciated.

1

There are 1 answers

2
Sampath On

In addition to consuming and receiving events, Run the code to send messages since the message sent will be displayed on the listening Output. The message is sent when the listener is active.

  • Create an Azure Relay Hybrid Connections from the MSDOC.

enter image description here

  • The code below creates a WebSocket client that connects to the Azure Service Bus Relay using the hyco-ws library and sends messages to the Azure Service Bus Relay using a WebSocket connection. Code reference form MSDOC

Code:

const WebSocket = require('hyco-ws');
const readline = require('readline')
    .createInterface({
        input: process.stdin,
        output: process.stdout
    });;

  
WebSocket.relayedConnect(
    WebSocket.createRelaySendUri(ns, path),
    WebSocket.createRelayToken('http://'+ns, keyrule, key),
    function (wss) {
        readline.on('line', (input) => {
            wss.send(input, null);
        });

        console.log('Started client interval.');
        wss.on('close', function () {
            console.log('stopping client interval');
            process.exit();
        });
    }
);

Output:

Sending message

enter image description here

Listening enter image description here