0

I just wanted to validate my setting. It seems to work, but I thought to validate my setting with you guys.

I have SignalR hosted in my website. And in my Startup.cs I do:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);  //may be no longer needed because I've set KeepAlive?
        GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);
        GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);

        // following setting is get from https://greenfinch.ie/2015/07/09/azure-licks-using-redis-cache-signalr/
        var redisConnection = ConfigurationManager.ConnectionStrings["RedisCache"].ConnectionString;
        // set up SignalR to use Redis, and specify an event key that will be used to identify the application in the cache
        GlobalHost.DependencyResolver.UseRedis(new RedisScaleoutConfiguration(redisConnection, "MyEventKey"));

        app.MapSignalR();
    }
}

Now, I consume it like this in my other web service:

HubConnection hubConn = new HubConnection(url);
...
...
...
hubConn.CreateHubProxy("NotifyHub").On<string>("Notify", (msg) => PushToQueue(msg));
hubConn.Start();

Is this seems right? Is that means SignalR connection timeout is 10 seconds (because KeepAlive is set to 10 seconds)?

Here is my usage diagram (imagine there are lots of traffic to the website and webserver and Azure needs to fire up another computer for both website and webserver)

                        url: www.blablabla.com                 url: services.anotherweb.com
--------                      -----------                             ---------------
| User |  --> Modify Data --> | Website | --> Trigger Web Service --> | Web Service |
--------                      -----------          |                  ---------------
                                                   |                        ^
                                                   |                        |
                                                   |     --------------------  
                                                   |     |                    
                                                   ------|---------------------
                                                         |                    |
                                                         |                    |
                                                         |                    v
                        url: www.blablabla.com           |     url: services.anotherweb.com
--------                      -----------                |            ---------------
| User |  --> Modify Data --> | Website | --> Trigger Web Service --> | Web Service |
--------                      -----------                             ---------------

Sorry for the silly question. Just found out about redis today and wanted to scale my website with SignalR.

Sam
  • 1,826
  • 26
  • 58

1 Answers1

2

SignalR currently provides three backplanes: Azure Service Bus, Redis and SQL Server, we can use Redis to distribute messages across a SignalR application that is deployed on multiple instances, as you did, and your configuration is ok. This article:SignalR Scaleout with Redis is a detailed tutorial, you can refer to it.

Is that means SignalR connection timeout is 10 seconds (because KeepAlive is set to 10 seconds)?

SignalR uses one of transport APIs: WebSockets, server-sent events, forever frame, or long polling to create a transport connection. And for all transports other than long polling, the SignalR client uses a function called keepalive to check for loss of connectivity that the transport API is unable to detect, your configuration GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10) indicates a keepalive packet will be sent every 10 seconds.

Fei Han
  • 26,415
  • 1
  • 30
  • 41
  • Hi Fred, thanks for replying, just curious `GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);` actually set in the server and **not** client. Is that ok? Does the client "somehow" know that it is 10 seconds? – Sam Sep 29 '17 at 09:43
  • The hub server sends a keepalive packet to the client every 10 seconds. For detailed information, please check [**Transport disconnection scenarios**](https://learn.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/handling-connection-lifetime-events#connection-lifetime-terminology-and-scenarios). – Fei Han Oct 02 '17 at 05:47
  • Thanks Fred for validating my code and explaining how keepalive works :) – Sam Oct 05 '17 at 03:43
  • I assume that most of these types of questions only apply if you are standing up your own SignalR server and they do NOT apply to the (Azure SignalR Service)[https://azure.microsoft.com/en-us/services/signalr-service/] which I assume abstracts worries about choosing a backplane and other details away from you. However, if that assumption were true, I'd expect more people to answer questions like this with, "Just use the Azure SignalR Service" so you don't have to worry about this. So, I'm uncertain if there is a difference? Is there a way to just see Stack Overflow Q&A for the service? – Larry Maccherone Oct 23 '18 at 18:51