How to add a strongly typed SignalR Hub when using Mangament
ZisisTsatsas opened this issue · comments
Can I add a strongly typed SignalR Hub when using Management on a serverless configuration?
I want to add a strongly typed hub in my signalr service to be used by the client, is this possible when using Management and ServiceHubContext?
If not how can invoke methods from clients? Send messages between clients or have clients add themselves to groups for example.
Although strongly typed hub is supported, client invocation is not supported yet. Duplicated: #1756
is there plans for it to be supported?
is there plans for it to be supported?
Yes
@ZisisTsatsas Sorry that I have found that I may misunderstand your problem. What you want to do in Call hub methods from clients, right? It's not convenient to achieve it only with Management SDK. We recommend you use Azure Functions with SignalR trigger.
-
Here is an example:
https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/BidirectionChat -
To use Azure Functions with SignalR trigger, you use Azure SignalR Service in serverless mode. To understand how serverless mode work, see https://learn.microsoft.com/en-us/azure/azure-signalr/concept-service-mode#serverless-mode
-
The following docs should give you an overview about how to use SignalR service in Azure functions https://learn.microsoft.com/en-us/azure/azure-signalr/signalr-concept-azure-functions
https://learn.microsoft.com/en-us/azure/azure-signalr/signalr-concept-serverless-development-config
Please note that Strongly typed hubs in SignalR is more of the data flow from server to client.
Feel free to ask more questions.
@Y-Sindo Is there a way to do this without Azure Functions? Currently, I am hosting SignalR alongside my API in an Azure WebApp and I am using Redis Stack to have consistency over different regions, but it has some issues so I want to switch to the Azure SignalR service
Yes, you can do this without Azure Functions. SignalR trigger is nothing more than a REST API server that handles client events. Therefore, you can also implement a REST API server to do this:
- See the REST API spec here: https://learn.microsoft.com/en-us/azure/azure-signalr/concept-upstream#serverless-protocols
- Additionally, the response body of invocation message can be a CompletionMessage in the SignalR protocol, which is serialized with a hub protocol used by your clients. Only JSON hub protocol and message pack hub protocol are supported. You can see the SignalR trigger code for an example to construct the HTTP response message for invocation message.