0

我需要在队列中获取最旧的消息年龄。在使用 wmi 的情况下有这样的属性:

myQueue.OldestMessageAgeSeconds

但是我必须在没有 wmi 的情况下这样做。找到这样的例子:

Function OldestMessageAgeSeconds(queueFormatName)
       Dim queueInfo
       Set queueInfo = CreateObject("MSMQ.MSMQQueueInfo")
       queueInfo.FormatName = queueFormatName
       Dim queue
       Set queue = queueInfo.Open(32, 0) 'Peek access mode
       If Err.Number > 0 then
              OldestMessageAgeSeconds = 0
       Else
              Dim message
              Set message = queue.PeekCurrent()

              Dim oldestMessageTime
              oldestMessageTime = Now
              Do While Not message Is Nothing
                     If message.ArrivedTime < oldestMessageTime Then
                           oldestMessageTime = message.ArrivedTime
                     End If
                     Set message = queue.PeekNext(False, false, 0)
              Loop

              Dim oldestMessageAge
              oldestMessageAge = DateDiff("s", oldestMessageTime, Now)
              OldestMessageAgeSeconds = oldestMessageAge
       End If
End Function

但这对我来说并不好,因为队列中有大量消息。

是否有另一种方法可以找到最旧的消息年龄?

非常感谢。

4

0 回答 0