简体   繁体   English

在IIS中部署带有ARR的signalR(应用程序请求路由)

[英]Deploying signalR with ARR in IIS (Application Request Routing )

We are using SignalR in Application. 我们在应用程序中使用SignalR。 There was an exception type of: 异常类型为:

Hub Server was unable to start. 集线器服务器无法启动。 Message:One or more errors occurred. 消息:发生一个或多个错误。 Stack trace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at ProjectName.TryStartHub(Object source, ElapsedEventArgs e) 堆栈跟踪:位于System.Threading.Tasks.Task.Wait处的System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)(位于ProjectName.TryStartHub处的System.Threading.Tasks.Task.Wait()处的Int32 millisecondsTimeout,CancellationToken cancellingToken) (对象来源,ElapsedEventArgs e)

While there was no error when we were testing at local in my system. 当我们在系统中本地测试时没有错误。 When we deployed it with ARR. 当我们使用ARR部署它时。 then there was an exception that was just because of ARR. 那么就有一个例外是仅仅因为ARR。 While we also removed the ARR and then tried it worked. 同时我们也删除了ARR,然后尝试了它。 But it is not working with the ARR. 但是它不适用于ARR。

Code is correct but there is configuration issue of SignalR with ARR. 代码正确,但是SignalR和ARR存在配置问题。

    public void InitializeHub()
    {
        appLog.Write("Initializing Hub Server");
        IHubProxy _hub;
        var querystringData = new Dictionary<string, string>();
        querystringData.Add("Key", "key1");
        hypervisorConnection = new HubConnection("url", querystringData);
        _hub = hConnection.CreateHubProxy("Hub");
        _hub.On<HypervisorCommand>("ExecuteHypervisorCommand", x => ExecuteHypervisorCommand(x));

        #region Initialize Hub Timer
        hHubTimer = new System.Timers.Timer();
        hHubTimer.Elapsed += new ElapsedEventHandler(TryStartHub);
        hHubTimer.AutoReset = false;
        hHubTimer.Interval = 1000;
        hHubTimer.Enabled = true;
        hHubTimer.Start();
        #endregion
    }

    private void TryStartHub(object source, ElapsedEventArgs e)
    {
        try
        {
            if (hConnection.State != ConnectionState.Connected)
            {
                hConnection.Start().Wait();
                appLog.Write("Hypervisor Hub server started.");
            }
        }
        catch (Exception ex)
        {
            appLog.Write("Hub Server was unable to start. Message:" + ex.Message + "\n Stack trace:" + ex.StackTrace);
        }
        hHubTimer.Interval = 30000;
        hHubTimer.Start();
    }

So, finally we solved this issue. 所以,终于我们解决了这个问题。 The issue was there in configuration of IIS load balancer ARR(Application Request Routing). IIS负载平衡器ARR(应用程序请求路由)的配置中存在问题。

1. First, Select the ARR form IIS Menu. 1.首先,从IIS菜单中选择ARR。 在此处输入图片说明 2. Go to the Proxy and set the response buffer threshold to 0. Why we have to set the response buffer size to 0? 2.转到Proxy并将响应缓冲区阈值设置为0。为什么我们必须将响应缓冲区大小设置为0? Here is the detail description : By default this is set to 256kb which means that it will buffer responses until they reach that amount. 这是详细说明:默认情况下,此设置为256kb,这意味着它将缓冲响应,直到响应达到该数量为止。 By setting this to 0 ARR will no longer buffer and SignlR will function correctly. 通过将此设置为0,ARR将不再缓冲并且SignlR将正常运行。

在此处输入图片说明

3. And then go to the load balancer and change the load balancer algorithm from "round robin" to the "Server variable hash". 3.然后转到负载平衡器,并将负载平衡器算法从“循环”更改为“服务器变量哈希”。 Now SignalR client every time will connect to the hub. 现在,SignalR客户端每次都会连接到集线器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM