Search code examples
azure-functionssignalrsignalr.clientasp.net-core-signalrazure-signalr

Connecting to serverless Azure SignalR service using Azure functions and their negotiate function


I have serverless Azure Functions (NodeJs) integrated to Serverless Azure SignalR service.

I can connect with Javascript just fine to SignalR via negotiate function in Azure functions.

Connection below is initialized to my function app, which returns the signalR uri and accessToken for it, which the @microsoft/signalr library knows how to use, and it internally connects to signalR using them

const appUri: string = process.env.FUNCTION_APP_URI as string
const connection: HubConnection = new HubConnectionBuilder()
  .withUrl(appUri)
  .build()
connection.on('newMessage', (message) => console.log(message))
connection.start()
  .then(() => console.log('SignalR listener started.'))
  .catch(console.error)

Everything works fine.

But how do I do the same from a .Net Core console app?

Is it possible to use the same negotiate function for .Net Core also? Or do I have to connect to signalR directly? Which library is the correct one for this:

  • Microsoft.AspNetCore.SignalR.Client
  • Microsoft.Azure.SignalR;
  • Some other?

Solution

  • I have serverless Azure Functions (NodeJs) integrated to Serverless Azure SignalR service.

    Please note that setting the Service Mode setting to Serverless only if you are using Azure SignalR Service through Azure Functions binding or REST API.

    For more information about Service modes of Azure SignalR Service, please check:

    https://learn.microsoft.com/en-us/azure/azure-signalr/concept-service-mode

    Besides, this doc shows how to broadcast real-time messages from console app, you can refer to it.

    https://learn.microsoft.com/en-us/azure/azure-signalr/signalr-quickstart-rest-api