I'm upgrading a .Net core 3.1 azure function which uses a ServiceBusTrigger, to a .Net 5.0 isolated process function. The function uses SignalR to broadcast real-time messages throughout the steps of the process--for example: "Opening file"... "Reading records - 10% complete"... "Preparing to display records", and so forth. Multiple messages are broadcast via SignalR during a single run of the function.
The .Net core 3.1 function signature was similar to this:
[FunctionName("MyFunction")]
public async Task RunTopic(
[ServiceBusTrigger("TopicName", "SubscriptionName", Connection = "ConnectionString")]
string message, ILogger log, ExecutionContext executionContext,
[SignalR(HubName = "Hub", ConnectionStringSetting = "SignalRConnectionString")]IAsyncCollector<SignalRMessage> signalRMessages
)
{ ... }
And, below is an example of the logic used to broadcast the messages:
await signalRMessages.AddAsync(
new SignalRMessage
{
Target = "newMessage",
Arguments = new[] { $"Message content" }
});
Upon converting the function to a .Net 5.0 isolated process function, I've noticed that the SignalR implementation is a bit different. I've found examples; however, they seem to address basic scenarios.
In a .Net 5.0 isolated process function, what steps are needed to allow multiple messages to be broadcast real-time via SignalR, during a single run of the function? The examples I've seen so far seem to allow a single message to be broadcast with each run of the function.
Here's an example of the method signature, after upgrading the function to a .Net 5.0 isolated function:
[Function("MyFunction")]
[SignalROutput(HubName = "Hub", ConnectionStringSetting = "SignalRConnectionString")]
public async Task<CustomMessage> Run(
[ServiceBusTrigger("TopicName", "Subscription", Connection = "ConnectionString")]
string message, FunctionContext functionContext)
{ ... }
public class CustomMessage
{
public string Target { get; set; }
public object[] Arguments { get; set; }
}
Additional info:
I came across this posted item which describes what I am asking: https://github.com/Azure/azure-functions-dotnet-worker/issues/179
Namely, the IAsyncCollector, supported in .Net Core 3.1, seemed to allow several different/unique messages to be sent over the course of the function running, as opposed to only the last message being sent, once the function completed. Alternatives are being considered at the moment, as comments in the above link indicate this behavior may not be supported in .Net 5.0 isolated process functions.