Skip to content

Instantly share code, notes, and snippets.

@andreasohlund
Created June 20, 2017 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasohlund/1c3b8471521fbfc1f3ab8c40f2fde75c to your computer and use it in GitHub Desktop.
Save andreasohlund/1c3b8471521fbfc1f3ab8c40f2fde75c to your computer and use it in GitHub Desktop.
using System;
using MSMQ;
class Program
{
static void Main(string[] args)
{
//add ref to mqoa30.tlb https://stackoverflow.com/a/8258952/236004
var localMsmq = new MSMQApplication();
var allActiveQueues = localMsmq.ActiveQueues;
foreach (var queue in allActiveQueues)
{
var queueName = queue.ToString();
var queueManagement = new MSMQManagement();
var machine = (Object) Environment.MachineName;
var formatName = (Object) queueName;
var format = (Object) null;
queueManagement.Init(ref machine, ref format, ref formatName);
if (queueManagement.IsLocal)
{
continue;
}
var outgoingQueue = (MSMQOutgoingQueueManagement) queueManagement;
// see https://msdn.microsoft.com/en-us/library/ms701455%28v=vs.85%29.aspx for mire details
var sendInfo = outgoingQueue.EodGetSendInfo();
Console.Out.WriteLine($"{outgoingQueue.FormatName} - {outgoingQueue.MessageCount}(messages)");
//see https://msdn.microsoft.com/da-dk/library/windows/desktop/ms705063(v=vs.85).aspx
foreach (var info in sendInfo)
{
var propertyName = info.ToString();
Console.Out.WriteLine($"{propertyName}: {sendInfo.Item(propertyName)}");
}
}
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment