.net - MSMQ MessageQueueException 启动后不久

标签 .net vb.net msmq

我有一个多用户计划应用程序,其中客户端将包含他们的更改的 msmq 消息发送到服务器应用程序,服务器应用程序处理它们,计算库存/时间短缺,然后向所有连接的客户端发送消息以更新他们的数据以显示变化。

除了一个一直困扰我的异常之外,这工作得很好。

这基本上只会在启动后立即发生在我们一些速度更快的 PC(配备 SSD、I7 等)上。

ExceptionInformation: System.Messaging.MessageQueueException
Stack:
   at System.Messaging.MessageQueue+MQCacheableInfo.get_ReadHandle()
   at System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32, Int32, MQPROPS, System.Threading.NativeOverlapped*, ReceiveCallback, System.Messaging.Interop.CursorHandle, IntPtr)
   at System.Messaging.MessageQueue.ReceiveCurrent(System.TimeSpan, Int32, System.Messaging.Interop.CursorHandle, System.Messaging.MessagePropertyFilter, System.Messaging.MessageQueueTransaction, System.Messaging.MessageQueueTransactionType)
   at System.Messaging.MessageQueue.Receive()
   at Europlanner_.MSMQHandler.ReceiveMessage()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.runTryCode(System.Object)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

如果他们在启动后一分钟左右打开应用程序,则不会出现错误。因此,尽管这确实不是破坏游戏的错误,但我还是想修复它。

我已经对异常进行了一些搜索,我猜它与权限有关,但奇怪的是它只在启动后不久发生。

出于测试目的,我尝试设置队列的权限,以便每个人和匿名登录都具有完全控制权。但这似乎没有帮助。

机器都在同一个域中,队列在域中我们的一台服务器上。

发生异常的代码如下:

Private Sub ReceiveMessage()
    While KeepReading
        Dim MSG As Message = ClientQue.Receive()
        If Not DateDiff(DateInterval.Minute, MSG.SentTime, Now) >= 1 Then
            HandleMessage(MSG)
        Else : DebugHandler.WriteLine(DebugTypes.Network, "Removed MSMQ message due to age. (Older than 1 minute") : End If
        LastServerCommunication = 0
    End While
End Sub

我自己的机器比用户的机器老一点,速度也慢一些,我个人似乎无法在自己的机器上重现这个错误。我可以使用用户机器进行测试的时间范围是有限的。

有没有人碰巧知道是什么导致了这个异常?

如果我需要发布任何其他信息,请询问。

感谢您的关注。

编辑以回答 Kjell-Åke 的问题:

我用这个小函数来检查服务是否启动:

Private Function QueueServiceStarted() As Boolean
    Dim Services As List(Of ServiceController) = ServiceController.GetServices().ToList
    Dim MSMQueue As ServiceController = Services.Find(Function(o) o.ServiceName = "MSMQ")
    If Not MSMQueue Is Nothing Then If MSMQueue.Status = ServiceControllerStatus.Running Then Return True
    Return False
End Function

编辑以添加异常消息:

"Unable to establish connection with Active Directory Domain Services. Verify that   there are sufficient permissions to perform this operation."

编辑:添加更多信息

在 Windows 日志中出现以下事件后,应用程序似乎可以正常工作。

"The Message Queuing service is online with Active Directory and fully operational."

所以基本上我猜问题变成了:为什么在我们更快的 PC 上发生这种情况需要这么长时间。

最佳答案

我遇到过这个问题,最后我使用事件日志触发器并等待 MSMQ 与广告服务器握手。

我只是厌恶在 try/catch/sleep 循环中反复尝试直到它出现的想法。 修复它可能有点太复杂,但我发现这是值得的。

这样您就可以构建代码以区分客户端计算机上的启动错误和 MSMQ 只是在等待 AD 服务器。

Message Queuing Active Directory Operation

Subscribe to Events in an Event Log

关于.net - MSMQ MessageQueueException 启动后不久,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15018989/

相关文章:

mysql - vb.net - Mysql 连接未使用 Sub 例程关闭

c# - 如何通过 P/Invoking 在 Windows 8/8.1 中以编程方式更改视觉主题?

vb.net - 将数学运算符分配给没有 IF 的变量 - System.MissingMemberException

c# - 向 MSMQ 发送序列化数据时抛出 InvalidCastException

c# - 仅在构造函数中设置类泛型值

c# - .NET:异步套接字,其回调在GUI线程上运行?

c# - Nservicebus 不在 msmq 中存储订阅者

c# - 如何防止 WCF 服务进入故障状态?

.net - 删除 wcf Web 服务起始页

c# - 使用正则表达式在 5 位数字后的 9 位数字中插入连字符