I’m working on migrating our Functions app from in-process model to isolated. I’ve encountered a dilemma with Serverless SignalR that isn’t documented (as far as I can tell).
Old Scenario (in-process)
With the in-process model, you can send messages to SignalR hubs programmatically. You pass an instance of SignalRMessage
into the parameters of your function and call it from there. (Microsoft docs)
[FunctionName("SomeFunction")]
public static async Task Broadcast([TimerTrigger("*/5 * * * * *")] TimerInfo myTimer,
[SignalR(HubName = "SomeHub")] IAsyncCollector<SignalRMessage> signalRMessages) // Instance in parameters
{
//...
await signalRMessages.AddAsync(someMessage);
}
This way you can invoke methods on signalRMessages
multiple times wherever desired.
New Scenario (isolated)
With the isolated model, you have to decorate an entire Azure Function with the SignalROutput
annotation so it sends the return value to the specified SignlR hub.
My problem is that programmatically calling a regular C# function that is annotated as SignalROutput
will not send the return value to the SignalR hub. This makes it impossible to apply the logic that I need to apply, because we send messages in multiple places in the same function. (Microsoft docs)
This is the function I’m calling programmatically
[SignalROutput(HubName = FunctionsConstants.SignalRAlarmNotificationsHub)]
public List<SignalRMessageAction> SendSignalRNotificationForAlarmMessage(AlarmMessage alarmMessage)
{
string alarmMessageJson = alarmMessage.ToJson();
return [
new SignalRMessageAction(FunctionsConstants.SignalRAlarmNotificationsHub) {
GroupName = GroupAll,
Arguments = [alarmMessageJson]
},
// proceed to send same message to multiple different groups
];
}
If I change the same function to an Azure Function with an HttpTrigger and trigger it that way, it does send the messages to SignalR.
Question
How do i send messages to SignalR programmatically (from code) in the new isolated worker model? I’m very much hoping it’s possible without having to somehow trigger actual Azure Functions in a ridiculously hacky way.
Thanks!