SignalR Scaleout using Sql Server (.net6) - signalr

I am trying to figure out how to use SignalR scaleout wit SqlServer backplane. Otherwise we are not able to use multiple instances in Kubernetes.
I looked up a Nuget Microsoft.AspNetSignalR.SqlServer but it is not there for NET6.
I also tried to find in docs, but this one talks about Redis backplane https://learn.microsoft.com/en-us/aspnet/core/signalr/redis-backplane?view=aspnetcore-6.0
Is it possible to use SQL Server and if so, how?
Thanks

Related

Is it possible to use SignalR to forward data from another server to your clients?

My previous experience with SignalR was only as a server, getting data from a database and then updating the webpages accordingly.
I was wondering if it is possible to use SignalR to connect to other servers that shares data via Websockets and then consolidating the data to send out to your own clients, also using SignalR? So something like a forwarder of sorts.
You can use the .net signalR client to hook nearly anything to the server. There can be difficulties with waking the server up, so it is important to check the behavior.
https://learn.microsoft.com/en-us/aspnet/core/signalr/dotnet-client?view=aspnetcore-5.0&tabs=visual-studio

SignalR Core scaling/hosting

I have some questions regarding SignalR Core on the server side;
My server is written in ASP.NET Core, and it uses SignalR for sending notifications to users. The server uses Controllers with endpoints that clients interact with.
1) Can I host the entire thing in Azure App Service and add the SignalR service to it? Or would it be better to split the SignalR code out to its own server, which is called from the "main" server when needed?
2) The SignalR Service has an option for "Serverless", which according to documentation doesn't support clients calling any server RPCs when in said mode. Could I run this thing in Serverless mode as I'm only using the sockets for sending notifications to the clients. Or is it reserved for Azure functions?
3) Is there a way to get the number of connections for a user in a SignalR hub? I would like to send a push message to the user if he doesn't have any connections to the server. If not - what is the recommended way of handling this? I was thinking of adding a singleton service that keeps count, but am unsure if this would work at scale, especially with the SignalR service.
Thanks.
1) Better use the Azure SignalR.
2) Use it with the hub.
3) If you use Azure SignalR, you can just see it from the portal. In the code, whenever you use Azure SignalR or not, you can save the user Id in some var and count the connections. If you have multiple hubs and servers, you need to do more (if using redis-backplane for example).

SignalR SQL Scaleout

We have two SignalR instances (different SignalR hubs hosted on separate servers and those servers are load balanced). We are planning to use SignalR Scaleout with SQL Server.
We have the following concerns
Use Common(single) database for both the signalr hubs (seperate signalr instance), is this fine?
Is it possible to generate signalr related tables under custom schema name in a database, based on the signalr instances?
That is the point of the backplane - a multitude of SignalR instances all using the same database. The only thing a backplane does is save messages from each instance to a central back store. Each instance will then poll the table for changes. Each instance will filter out it's own saved messages and detect the new messages from other instances, and will then send the new messages from other instances to the clients connected to it.
No. The SignalR schema name is hardcoded and is not configurable.

SignalR different applications on same backplaneDB

We host different MVC5 web applications for the intranet(500 employees) on server farms. We want to lightly use signalR 2.2 with SQL Server service broker backplane, mainly for server broadcast. We want to use the same backplane DB for different applications, all applications having acces to the backplane DB server.
Question : 1-Is it to avoid in terms of performance, I didn't see any good practice guidance and it seems to work technically. 2-If a message is broadcast to application1 clients, will it be sent to clients of Application2 also?3-What would be the advantages of using separate backplane DB for each application?
Up to version 2.x, I don't think that is a good idea because it would probably be inefficient. It might work, but the current mechanism would broadcast all messages to all apps using the same connection string (= same server + same database). There is no way to segregate applications on the same database. It looks like there is a plan for it in future versions, but as of today it's probably not recommended.

ASP.NET application load balancing

I have an ASP application sitting on 2 servers, using a db in SQL Server 2012. The SQL Server uses AlwaysOn Availability groups but when these failover the client connecting to the ASP.NET application terminates. I have looked into the SQL driver which as it turns out the app is using SqlClasses so not using ODBC driver (from what I have deduced I presume that logic is sound but correct me if I'm wrong).
Another suggestion has been made that I load balance the 2 app servers and that will seamlessly allow failover underneath without the client loosing connection, is this a viable way to go? We don't have much control over the applications code to ask it to try the connection again after failing....
Many thanks in advance.
Try defining the failover partner in your connection string.
Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;
Initial Catalog=myDataBase;Integrated Security=True;
And also check out MultiSubNetFailover property in .NET 4.5

Resources