Saturday, October 22, 2005

MSMQ Queue Message Count in VB6

Today I need to find a simple and easy way to get the number of messages in a private MSMQ Queue on a remote server.

After googling for a while, there seems to be three ways.
  1. MSMQ 3.0 COM Object (via the MSMQManagement and MSMQQueueManagment objects)

  2. WMI

  3. MSMQ Admin API

A. WMI is cool, but I’d rather a more direct method.

B. The MSMQ Admin API is not fun (to say the least) to call directly from VB. A C++ wrapper would really be needed. So this method is tabled for now.

C. MSMQ 3.0 COM is very cool, but requires XP or 2003 (and we’re still on Win2K in production. But we are moving toward XP in the very near future…)


So MSMQ 3.0 COM looks like the only viable method given the time and resources available. And it will give our XP rollout that much more oomph…


Here are come relevant links I found while searching, as well as a VB6 MSMQ 3.0 queue message count sample.

Counting messages in Queue - the .NET version
Counting the number of messages in a queue
How to GET the message count of MSMQ in .NET without Performance Counter?
FILE: MSMQ Local Admin API
MSDN - Message Queuing COM Components

VB6 Sample using MSMQ 3.0 (XP and Win2003)

‘Add Reference to “Microsoft Message Queue 3.0 Object Library”

Private Function GetPrivateQueueMessageCount(sServerName as string, sQueueName as string) as Long

  Dim Mgmt As MSMQManagement
  Set Mgmt = New MSMQ.MSMQManagement
      
  Mgmt.Init sServerName, ,"DIRECT=OS:" & sServerName & "\PRIVATE$\" & sQueueName
  
  GetPrivateQueueMessageCount = Mgmt.MessageCount

End Function

No comments:

Post a Comment

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...