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?
0
votes
Why do you need SignalR between the web server and the api server? Can't you do simple http calls between them?
– Francesc Castells
The API server should be able to push information to the web server which then pushes it to the web clients. I don't want to constantly poll the API server for new information.
– Pascal R.
I understand, but why can't the web server expose a Post endpoint to receive this information? Why does it have to be SignalR?
– Francesc Castells
Alternatively, Api Server could send messages to Web Server through a queue. Both of these techniques would allow you to eventually separate the SignalR server from the web server if you need it to control scaling for example.
– Francesc Castells
1 Answers
1
votes
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://docs.microsoft.com/en-us/aspnet/core/signalr/hubcontext.
From a different host, use the SignalR client, see here: https://docs.microsoft.com/en-us/aspnet/core/signalr/dotnet-client.