API Server as SignalR client - asp.net-core-mvc

I've got an ASP.NET MVC Core application which is served from a web server. The web server has a SignalR Hub and gets its data from a dedicated API server. Is it possible to register the web clients AND the API server as SignalR clients, so that the API server can push data directly to the web clients?

Yes. From the same host, inject a IHubContext<YourHub> into your controller classes and from there you can send messages to any connected clients, see more here: https://learn.microsoft.com/en-us/aspnet/core/signalr/hubcontext.
From a different host, use the SignalR client, see here: https://learn.microsoft.com/en-us/aspnet/core/signalr/dotnet-client.

Related

Updating a Web Socket from Outside the Web Socket App

If I have an app (let's Express.js app) with a web socket (socket.io) and I want to send message to a client from a different server app, what is the best way to go about that.
Let's assume that both apps are on a public cloud and running on separate containers or VMs. What's the best way to ensure that the message is sent to the right web socket app instance that holds the connection to the client?
You can use redis to ensure that client will get the message no matter which instance of app is sending the message.
But if your other app is a completely different app and does not start a socket server, You can still use socket.io emitter (along with redis adaptor) to send messages to clients without creating another socket server.

Enable signalr to accept WS connections

I have created a dotnet core signalr project, and I want to allow other users to connect on the signalr web socket like I can do it when I connect on:
wss://echo.websocket.org
Currently, signalr generates ID when creating the negotiation, and when switching on wss it uses that id, but it is causing a problem when using external connections.
So, is it possible to tell SignalR not to generate the id when creating the websocket server, and also to accept external ws connections ?
try to use dotnet core websockets
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/websockets?view=aspnetcore-2.2

Does each SignalR hub has a dedicated websocket

Assuming both browser & Server supports a web-socket connection.
If I've got 2 hubs on my SignalR server. and my SignalR client connects to both. does that mean that my signalR client will open up 2 separate web-socket connections to the server?
In SignalR v2+, hubs will share the same connection. I've had systems with connections to 4+ hubs without performance issue.
Question is a bit of a duplicate of: Multiple signalR connections/hubs on your website

One Web API calls the other Web APIs

I have 3 Web API Servers which have the same functionality. I am going to add another Web API server which will be used only for Proxy. So All clients from anywhere and any devices will call Web API Proxy server and the Proxy server will transfer randomly the client requests to the other 3 Web API servers.
I am doing this way because:
There are a lot of client requests in a minute and I can not use only 1 Web API server.
If one server was dead, clients can still send request to the other servers. (I need at least 1 web servers response to the clients )
The Question is:
What is the best way to implement the Web API Proxy server?
Is there a better way to handle high volume client requests?
I need at least 1 web server response to the clients. If I have 3 servers and 2 of them are dead.
Please give me some links or documents that can help me.
Thanks
Sounds like you need a reverse proxy. Apache HTTP Server and NGINX can be configured to act as a load balanced reverse proxy.
NGINX documentation: http://nginx.com/resources/admin-guide/reverse-proxy/
Apache HTTP Server documentation: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
What you are describing is call Load Balancing and Azure (which seems you are using from your comments) provides it out of the box both for Cloud Services and Websites. You should create as many instances as you like under the same cloud service and open a specific port (which will be load balanced) under cloud service endpoints.

Can SignalR be used to update clients which are servers by itself?

I'm trying to implement a Server which is a Asp.Net WebApi. This server is accessed by so many child services(let it be web servers). Can SignalR be used to update these child servers so that the child servers can update all the clients attached to them?
SignalR is a Server <> Client technology, it can be used Server <> Server but its better to use a Service bus like nServicebus or MQ to pub / sub between services.
edit: If its for scalability only you can use SignalR scaleout features

Resources