Hello Sathasivam, Logesh,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that your need similar "InvocationContext" to "SignalRInvocationContext" to check if a SignalR Active Connection is still active or not within .Net 8 Isolated SignalRTrigger Azure Function App.
Therefore, in the .NET 8 Isolated worker model, the SignalRInvocationContext
does not provide a direct method to check if a connection is still active. but, you can use the SignalRConnectionInfo
object to get the connection information and then use the SignalRService
to check the connection status. Try this sample code:
public class Function1
{
private readonly ISignalRService _signalRService;
public Function1(ISignalRService signalRService)
{
_signalRService = signalRService;
}
[FunctionName("Function1")]
public async Task Run([SignalRTrigger] SignalRInvocationContext invocationContext)
{
var connectionId = invocationContext.ConnectionId;
var hubName = invocationContext.HubName;
var connectionExists = await _signalRService.ConnectionExistsAsync(hubName, connectionId);
if (connectionExists)
{
// Your code logic here
}
}
}
In this code, ISignalRService
is a service that you would need to implement. This service would use the Azure.SignalR.Management
package to interact with the Azure SignalR Service and check if a connection exists.
Remember to replace Function1
and hubName
with your actual Azure Function and SignalR hub names. Also, you would need to register ISignalRService
in your startup class.
Accept Answer
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.
Best Regards,
Sina Salam