I beleive I have some mis-conceptions here in how Azure SignalR is meant to work when deploying an Azure Function that uses a SignalR Output Binding.
My environment:
1 - Azure Function which does some work and then sends a message to the SignalR service.
2 - A NET Core Web App is connected to Azure SignalR service and should receive these notifications.
The MS examples seem to suggest that the Net Core Webb App has to negotiate for a token and connect directly with the Azure Function in order to receive those messages. But this is now what I'm trying to achieve.
Given both applications connect with Azure SignalR service using the secure key/connection string, I would have expected Azure to act as the middle man and pass messages between one end to the other. Is this correct or have I got this competely wrong?
As a basic exmaple: Azure Function is configured similar to below where I receive a message from a service bus queue, on receipt of this message I then send the same message to Azure SignalR Service:
[FunctionName("My-Function-Name")]
public async Task RunAsync([ServiceBusTrigger(
"sampleQueue", Connection = "AzureServiceBusConnetion")]
string message,
[SignalR(HubName = "macroHub")] IAsyncCollector<SignalRMessage> signalRMessage,
ILogger logger)
{
logger.LogInformation($"C# ServiceBus queue trigger function processed message: {message}");
await signalRMessage.AddAsync(
new SignalRMessage
{
Target = "newMessage",
Arguments = new[] { message }
});
}
So from the above, no method required for negotiate or supplying any connection to an external client with a token i.e. I dont expect to have to connect my NET Core Web App directly to this Azure function. The message is simply sent to the Azure Signal service and Azure grabs this message.
Next, the NET Core Web App is connected to Azure SignalR using the Nuget package and a local Hub class is configured. On one of the pages of my NET Core Web App, I connect to the local Hub via JavaScript and should receive the message routed through Azure after it was sent out from the Azure Function.
NET Core Web App:
public class MacroHub : Hub
{
public async Task ReceiveMessage(string message)
{
await Clients.All.SendAsync("newMessage", message);
}
}
Sample JS in the Net Core Web App:
const connection = new signalR.HubConnectionBuilder()
.withUrl("/macroHub")
.withAutomaticReconnect()
.build();
connection.on("newMessage", (message) => {
alert(message)
});
This is not really a question about the code as such, I've had SignalR working fine before when using it locally in just one NET Core Web App, but I'm trying to utilise the Azure SignalR service in order to connect messages sent from an Azure Function through the Cloud and then receive those messages in the Net Core Web App.
Everything I've tried so far doesnt show any activity, neither the Web App of the Azure portal shows any logs or events for messages received.