Skip to content

Instantly share code, notes, and snippets.

View Lercher's full-sized avatar

Martin Lercher Lercher

View GitHub Profile
@Lercher
Lercher / MQCounter.vb
Last active July 25, 2017 20:38
Counting messages in a Microsoft Message Queue (msmq). About 25k times per second on a 2011 core i7 box with ssd.
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Public Class MQCounter
' see https://github.com/hibernating-rhinos/rhino-esb/blob/master/Rhino.ServiceBus/Msmq/MsmqExtensions.cs
' see http://ayende.com/blog/3884/unmanaged-api-fun-finding-out-msmq-subqueues-names-in-c
Public Shared Function Count(Q As String, Host As String) As UInteger
Dim props = New MQMGMTPROPS With {.cProp = 1}
props.aPropid = Marshal.AllocHGlobal(4) : Marshal.WriteInt32(props.aPropid, PROPID_MGMT_QUEUE_MESSAGE_COUNT)