【问题标题】:SignalR intermittently stops when in Azure production slotSignalR 在 Azure 生产槽中间歇性停止
【发布时间】:2016-08-30 21:17:37
【问题描述】:

我在 Azure 中有一个 Web 应用程序,它有 2 个部署槽。一个插槽用于开发目的;另一个插槽用于生产目的。

我在我的一个控制器中制作了一个 SignalR 集线器(自托管)。基本上,这个控制器的作用是负责将记录记录到我的 Azure DB 中。特别地,该控制器用于控制用户何时打开和发送电子邮件和/或点击特定链接。

SignalR 集线器用于向所有“连接的用户”发送向下推送通知。

当我在我的开发槽上测试它时;一切都按预期工作。

但是,只要我将它换到我的生产槽;奇怪的行为开始发生。要么一些通知来了;有些没有(基本上永远不会接触到客户);或者通知来晚了。

现在我不知道如何解决这个问题。我不明白我的代码中是否有任何错误(或者我在做一些根本错误的事情)。

我需要一些帮助来了解为什么这件事会间歇性停止;或者只是似乎不起作用。

重要说明...我还在我的两个部署槽中启用了 WebSocket。

还有;消费者是 WinForm 客户端。

现在这是我实际发送消息的地方(推送通知到相应的 ConnectionID):

AddToTblEmailEventDB(SentEmail, true, strEventOpen, strRecipientCookie);
//Save is done in this function 
string strBody = Helper.HtmlHelper.OpenJsonSerializer(SentEmail);
List<string> lstConnectionIDsToSendTo = new List<string>();

if (UserHandler.ConnectedUsers != null)
{
    for (int i = 0; i < UserHandler.ConnectedUsers.Count; i++)
    {
        if (UserHandler.ConnectedUsers.ElementAt(i).EmailAddress == SentEmail.tbl1Merges.AspNetUser.Email.ToString())
        {
            lstConnectionIDsToSendTo.Add(UserHandler.ConnectedUsers.ElementAt(i).ConnectionID);
        }
    }
}
//Actual Sending down happens here below....
if (lstConnectionIDsToSendTo.Count > 0)
{
    for (int i = 0; i < lstConnectionIDsToSendTo.Count; i++)
    {
        //Start sending the messages down to the devices
        hubContext.Clients.Client(lstConnectionIDsToSendTo.ElementAt(i)).updateMessages(strBody);
    }
}

现在这是基本上将消息(JSON 格式)发送给客户端的代码:

HubProxy.On(Of String)("updateMessages", Sub(message)
     Me.Invoke(DirectCast(
               Sub()

                If DateTime.Now < dtmHideNotification Then
                    Exit Sub
                End If

                   strJSONData = message  
                   'Display
                    If strJSONData <> String.Empty Then
                    strJSONData = "[" & strJSONData & "]"
                    strJSONData = strJSONData.Replace(JSON_QUOTE, """") '&quot;
                        dvNotifications = GetNotifications(strJSONData)

                        If dvNotifications IsNot Nothing Then
                            strSubject = dvNotifications(0).Item("Subject")
                            strType = Trim(dvNotifications(0).Item("Type"))
                            strDateTime = (dvNotifications(0).Item("Date"))
                            strRecipient = dvNotifications(0).Item("Recipients")
                            strEmailSendID = Trim(dvNotifications(0).Item("EmailSendID"))
                            If dvNotifications.Table.Columns("LinkClicked") IsNot Nothing Then
                                strLinkClicked = CStr(dvNotifications(0).Item("LinkClicked"))
                            Else
                                strLinkClicked = String.Empty
                            End If
                            If CInt(strRecipient) = 1 Then
                                strRecipient = dvNotifications(0).Item("EmailAddress")
                            Else
                                'strRecipient = "Someone"
                                'Dutt 7/12/15 Instead of someone , displaying "RecipientName or .."
                                strRecipient = dvNotifications(0).Item("EmailAddress") & " or..."
                            End If

                            If (strLinkClicked.Length > 20) Then
                                strLinkClicked = strLinkClicked.Substring(0, 20) & "..."
                            End If

                            Select Case strType
                                Case "O"
                                    strType = "Opened"
                                Case "C"
                                    strType = "Clicked"
                                Case "M"
                                    Exit Sub 'If there is a Merge taking place, then need to skip this iteration of the loop (because we don't want to show it)
                                Case Else
                                    'Do nothing Keep as same
                            End Select

                            Dim CustomNotification As New CustomNotification
                            CustomNotification.TopMost = False
                            CustomNotification.lblSubject.Text = IIf(strSubject = String.Empty, "[No Subject]", strSubject)
                            CustomNotification.EmailSendID = strEmailSendID
                            CustomNotification.pctIcon.Visible = True


                            CustomNotification.UserName = GetUserEmail()
                            CustomNotification.Password = GetUserPassword()

                            If strType <> String.Empty Then
                                If Trim(strType) = "Opened" Then
                                    CustomNotification.pctBox.Image = My.Resources.glyphicons_52_eye_open
                                   CustomNotification.lblContent.Text = strRecipient & " has " & strType.ToLower() & " this " & strDateTime
                                End If

                                If Trim(strType) = "Clicked" Then
                                    CustomNotification.pctBox.Image = My.Resources.glyphicons_51_link
                                   CustomNotification.lblContent.Text = strRecipient & " has clicked on" & " " & strLinkClicked & " " & strDateTime
                                End If
                            End If

                            CustomNotification.ShowDialog()
                            If CustomNotification.CloseTemporarily Then
                                If CustomNotification.CloseTemporarily Then
                                    'Hide the form
                                    CustomNotification.Close()
                                    dtmHideNotification = DateTime.Now.AddMinutes(2)
                                    Exit Sub
                                End If
                            End If
                            'Next
                        End If
                    End If
End Sub, Action))
End Sub)

请注意,WinForm 使用者是一个 VB.NET 表单;它所做的一切都连接到集线器,等待发送任何消息。

我不知道这是哪里出错了!

【问题讨论】:

    标签: c# vb.net winforms azure signalr


    【解决方案1】:

    您是否尝试过关闭 ARR Affinity?负载均衡器可能会一直将您的流量发送到它最初连接的机器。

    【讨论】:

    • 我以前没有遇到过这个 ARR Affinity 问题。不过我现在就试试。
    • 确保从浏览器中删除 ARRAffinity cookie 并在两个部署上关闭 ARR Affinity,然后进行测试。
    • 现在只是在开发槽上测试这个....我现在似乎得到了推动....不能太确定。稍后将交换以确认。
    • 这似乎奏效了。到目前为止,它在生产中运行良好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多