I'm currently migrating my azure functions from .NET 6 to 8 in an isolated worker model. Below is an example of how my real code works. basically the signalR is used to send messages to the front end on the progress of a long running queue function which no longer works on .NET 8 because I can only return one single message as a return SignalRMessageAction. is there a way to send more than one messages in a sequential order? either through separate queues or call another signalR message function?
[Function("PerformBackgroundJob")]
[SignalROutput(HubName = "progress", ConnectionStringSetting = "AzureSignalRConnectionString")]
public SignalRMessageAction PerformBackgroundJob(
[QueueTrigger(LibraryConstants.testQueue, Connection = "connectionstring-azure-storage")] string JobId)
{
var msg = new SignalRMsg();
_logger.LogInformation("PerformBackgroundJob started");
Stopwatch sw1 = new Stopwatch();
sw1.Start();
List<ProcessFileResponse> response = new List<ProcessFileResponse>();
msg = new SignalRMsg()
{
UserId = JobId,
Target = "taskStarted",
Arguments = new object[] { "PerformBackgroundJob started" }
};
//Send a message here
//SendMessage(msg);
_logger.LogInformation("PerformBackgroundJob data reviewed");
for (int i = 0; i < 100; i++)
{
msg = new SignalRMsg()
{
UserId = JobId,
Target = "taskProgressChanged",
Arguments = new object[] { i + 1 }
};
//Send a message here
//SendMessage(msg);
Thread.Sleep(200);
}
sw1.Stop();
TimeSpan ts = sw1.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
ProcessFileResponse outResponse = new ProcessFileResponse();
outResponse.Errors = 0;
outResponse.Warnings = 0;
outResponse.Status = 1;
outResponse.TabName = "Background action";
outResponse.Message = $"RunTime: {elapsedTime}";
response.Add(outResponse);
_logger.LogInformation("PerformBackgroundJob completed");
//this is The only message that is visible
return new SignalRMessageAction("taskEnded")
{
Arguments = new object[] { response },
UserId = JobId
};
}
I tried to use a separate function to send messages but it doesn't work, or maybe I'm calling the function in an incorrect way.
[Function(nameof(SendMessage))]
[SignalROutput(HubName = "progress", ConnectionStringSetting = "AzureSignalRConnectionString")]
public static SignalRMessageAction SendMessage(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] SignalRMsg req)
{
return new SignalRMessageAction(req.Target)
{
Arguments = req.Arguments,
UserId = req.UserId
};
}
public class SignalRMsg
{
public string UserId { get; set; }
public string Target { get; set; }
public object[] Arguments { get; set; }
}
