aspnet / SignalR

[Archived] Incredibly simple real-time web for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
2.38k stars 446 forks source link

I receive messages from my local Hub but not messages via Azure SignalR service #3349

Closed ryancole closed 5 years ago

ryancole commented 5 years ago

Hi folks,

I've got a setup that I'm trying to make sense of. It still hasn't "clicked" as to how Azure's SignalR service works in conjunction with my local ASP.NET Core SignalR Hub.

The moving parts that I have

I have my local ASP.NET Core SignalR server. It uses the Azure SignalR extension, which as I understand it offloads the actual transmission part of SignalR to Azure - so websocket, etc.

I also have the Azure SignalR Service up and running. It doesn't seem to have too many settings - it just kind of is running out there.

I've got a JavaScript browser client that uses @aspnet/signalr client library. It connects to my local ASP.NET Core SignalR server, which redirects it to Azure's SignalR service and opens the WS connection between browser and Azure.

Last, I've got my Azure Functions application that uses the SignalR Binding to broadcast messages to all clients. This binding connects directly to Azure using the connection string provided by the Azure portal. So this function doesn't connect to my local ASP.NET Core SignalR server, as I understand it.

My issue / confusion

For some reason, my browser client is not receiving messages that are broadcast from the Azure Functions SignalR binding. If I invoke a SignalR function from the browser client, it'll receive the broadcasted response - other browser clients will see it too. So, it looks like the clients that connects to my local ASP.NET Core SignalR hub all see each others messages. When broadcasting from my Function application, which connects directly to Azure, not through my local hub, my browser clients don't receive the event.

I used Fiddler to capture the HTTP requests, and I can see that the Function SignalR binding is indeed sending the POST request to Azure SignalR and receiving the Accepted response.

I'm not getting errors from anything, I'm just not receiving any messages that are dispatched from my Azure Function SignalR binding.

Question

Should this configuration of mine be working, or do I have something fundamentally incorrect about how I've got this setup?

ryancole commented 5 years ago

Holy cow, I just figured it out. I've been at this for about a week and a half now.

In the binding, when you specify hub name, you have to append hub to the name. I noticed that the @aspnet/signalr JS client was appending hub to the end of the name of my hub that I specify on the browser side of things. In my Functions binding, if I manually add hub to the end of my actual hub name, it works.

I must be doing something out of the ordinary though because I saw no mention of this anywhere, and none of the sample projects seem to do this. I'm unsure what the difference between what I'm doing is, though. I haven't seen any samples of using a local ASP.NET Core SignalR server with Azure SignalR service and Azure Functions. All the Azure Functions samples I've seen go the serverless route, and so I've not yet seen a sample exactly like mine - maybe that's where the difference lies?

ryancole commented 5 years ago

Oh no I see. It's taking the name of the hub from the class name. I don't know why I for some reason thought my hub was named "Functions" but my class is "FunctionsHub". Dang. A week out of the window due to that! haha

BrennanConroy commented 5 years ago

Glad you figured it out!