How to clear outgoing MSMQ queue

Is there any way to clear the outgoing queue. It does not seem that I can do this with the MMC snap-in, and when I try to clear it in the code, I get a Format name is invalid error message on which it sends messages, so they will never be sent, however the queues filled maximum storage space for MSMQ, so every time my application tries to send another message, I get an insufficient resources exception.

I tried the following formats and all of them fail with the exception Format name is invalid

DIRECT = OS: COMPUTER \ private $ \ queuename
OS: COMPUTER \ private $ \ queuename
COMPUTER \ private $ \ NameQueue

+6
msmq
source share
3 answers

You can clean it manually from the MMC snap-in. MSMQ gets very mean when it reaches storage limits, so many operations will fail with "permission enabled", etc.

A long-term solution, obviously, is to change the configuration, so there is enough storage space for your specific usage patterns.

Edit: Perhaps there may be a limitation in the managed API related to administrator capabilities and remote queues. Take a look at this article by Ingo Rammer. It even includes the p-invoke example.

+6
source share

You can use managed code to clear the outgoing queue:

 using (var msgQueue = new MessageQueue(GetPrivateMqPath(queueName, remoteIP), QueueAccessMode.ReceiveAndAdmin)) { msgQueue.Purge(); } 

in which GetPrivateMqPath:

 if (!string.IsNullOrEmpty(remoteIP)) return String.Format("FORMATNAME:DIRECT=TCP:{0}\\private$\\{1}", remoteIP, queueName); else return @".\private$\" + queueName; 

QueueAccessMode.ReceiveAndAdmin points to an outgoing queue.

+3
source share

You can try FORMATNAME:DIRECT=OS:computer\PRIVATE$\queuename .

+1
source share

All Articles