如何获取仅包含消息的队列名称,以及如何计算在控制台应用程序中具有消息的每个队列上的消息?

问题描述:

如何获取仅包含消息的队列名称以及如何计算每个有消息的队列上的消息数量以及如何在控制台应用程序中打印消息正文?



我尝试了什么:



How do I get the name of the queues with only messages and how do I count the number of messages on each queues which has messages and how do I print message body in console application?

What I have tried:

var q = MessageQueue.GetPrivateQueuesByMachine(machineName);





现在这将为我提供所有队列的列表。但我只需要那些有消息的东西,我需要指望每个队列中有多少消息和消息体。



Now this will give me the list of all queues. but I need only those which has message and I need to count on each queues how many messages are there and message body.

MSDN帮助页面提供有关的MessageQueue ;你有解决问题所需的一切:

https://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.getprivatequeuesbymachine%28v=vs.110%29.aspx [ ^ ],

MessageQueue类(System.Messaging) [ ^ ],

MessageQueue.GetAllMessages方法(System.Messaging) [ ^ ]。



注意 GetAllMessages 函数的最后一个链接。它返回消息数组,您可以使用它来查看是否有消息。只需调用数组的属性长度



不清楚你的意思是有多少消息和邮件正文;这个表达式在语法上和逻辑上都不正确。无论如何,获取消息数组并查看你想要的任何内容。



-SA
MSDN help page provide comprehensive information on MessageQueue; you have all you need to solve your problem:
https://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.getprivatequeuesbymachine%28v=vs.110%29.aspx[^],
MessageQueue Class (System.Messaging)[^],
MessageQueue.GetAllMessages Method (System.Messaging)[^].

Note the last link to the GetAllMessages function. It returns the message array, which you can use to see if there any messages. Just call the array's property Length.

It's not clear what you mean by "how many messages are there and message body"; this expression is not grammatically and logically correct. Anyway, get the message array and look at whatever you want.

—SA