I am a little bit confused on how my console application connects to Azure SignalR Server to receive the notifications that I am sending through my ASP.NET Core Web API application.
In the startup of my API I do what is needed:
services.AddSignalR().AddAzureSignalR();
app.UseAzureSignalR(routes =>
{
routes.MapHub<NotificationHub>("/notifications");
});
AddAzureSignalR() method connects to the Azure SignalR server via my defined connectionstring in my appsettings.
But as I saw in many examples, to get connected with my console application, I need to do the following:
var connectionBuilder = new HubConnectionBuilder()
.WithUrl("http://localhost:5000/notifications")
.Build();
await connectionBuilder.StartAsync();
connectionBuilder.On<string, string>("broadcastNotification", (name, message) =>
{
Console.WriteLine($"Name: {name}, Message: {message}");
});
What are the reasons that my console application connects to the Azure SignalR server through my API and not directly? Security or by design?
What are the reasons that my console application connects to the Azure SignalR server through my API and not directly? Security or by design?
Based on your description and code, it seems that you have a hub server and integrate with Azure SignalR Service.
In this kind of scenario similar as this official example demonstrated, the service mode of your Azure SignalR Service would be default mode. In this mode, your application works as a typical ASP.NET Core (or ASP.NET) SignalR application, and client would requires hub server to get connected as you did.
For more information about service modes and how to choose the right service mode, please check this doc: