我必须将VB 6.0应用程序移植到VB.Net(Framework 3.5).该应用程序大量使用MSMQ.我试图弄清楚使用WCF比良好的System.Messaging有什么好处.使用System.Messaging时是否有任何潜在的showstoppers?
我知道还有其他问题,但实际上并没有回答这个问题.
我的守则是:
using (var mQ = new MessageQueue(qPath))
{
Console.WriteLine("machine: {0}, name : {1}, path : {2}", mQ.MachineName ,mQ.QueueName, mQ.Path);
Console.WriteLine("message count : {0}",mQ.GetAllMessages().Count());
}
Run Code Online (Sandbox Code Playgroud)
当我在本地队列上尝试GetAllMessages()时,当然一切正常:
string qPath = @".\private$\queueName";
Run Code Online (Sandbox Code Playgroud)
但是,当我在同一个域上的远程计算机上尝试队列时,我只能使用计算机名称成功ping通,我收到此错误:
Invalid queue path name. at System.Messaging.MessageQueue.ResolveFormatNameFromQueuePath
Run Code Online (Sandbox Code Playgroud)
我试过了:
string qPath = @"remoteMachineName\private$\queueName";
string qPath = @"remoteMachineName.qualified.net\private$\queueName";
string qPath = @"DIRECT=OS:remoteMachineName.qualified.net\private$\queueName";
string qPath = @"DIRECT=OS:remoteMachineName\private$\queueName";
string qPath = @"DIRECT=OS:ip.ad.re.ss\private$\queueName";
string qPath = @"DIRECT=TCP:ip.ad.re.ss\private$\queueName";
Run Code Online (Sandbox Code Playgroud)
所有这些都给了我同样的错误.
Web上的文档说明如果您知道完整的"路径",就可以找到私有队列.
这是真的?如果是这样,如何编译完整路径?
干杯
使用这些System.Messaging类,如何将msmq消息(在本例中为有害消息)移动到子队列?
看起来这应该很简单,但我无法弄明白.
在.NET上的MSMQ中,我使用MessageEnumerator来查看队列中的所有消息.我想删除符合特定条件的邮件.
当我调用MoveNext来逐步执行队列时,我得到一个布尔值来告诉我当前消息是否存在.但是,当我执行RemoveCurrent时,如何知道删除后的当前消息是否存在?检查Current并处理异常的唯一方法是什么?
这是一个示例,我使用简单的条件删除超过一年的消息.假设队列是在别处创建的,并使用MessageReadPropertyFilter.ArrivedTime = true进行设置:
private void RemoveOldMessages(MessageQueue q)
{
MessageEnumerator me = q.GetMessageEnumerator2();
bool hasMessage = me.MoveNext();
while (hasMessage)
{
if (me.Current.ArrivedTime < DateTime.Now.AddYears(-1))
{
Message m = me.RemoveCurrent(new TimeSpan(1));
// Removes and returns the current message
// then moves to the cursor to the next message
// How do I know if there is another message? Is this right?:
try
{
m = me.Current;
hasMessage = true;
}
catch (MessageQueueException ex)
{
hasMessage = false;
}
}
else …Run Code Online (Sandbox Code Playgroud) 我创建了一个通过MSMQ发送消息但在执行时获得异常的函数.以下是我的功能.
public void SendMessageToQueue(ChessQueue chessQueue)
{
MessageQueue queue = null;
Message m = null;
if (!MessageQueue.Exists(".\\Private$\\" + chessQueue.QueueName))
{
queue = new MessageQueue(".\\Private$\\chessqueue");
chessQueue.Messages = new List<MessageObject>();
chessQueue.Messages.Add(chessQueue.Message);
queue.Formatter = new BinaryMessageFormatter();
m = new Message();
m.Body = chessQueue;
}
else
{
queue = new MessageQueue(".\\Private$\\" + chessQueue.QueueName);
queue.Formatter = new BinaryMessageFormatter();
m = queue.Receive();
ChessQueue ExistingChessQueue = m.Body as ChessQueue;
ExistingChessQueue.Messages.Add(chessQueue.Message);
m.Body = ExistingChessQueue;
}
queue.Send(m);
// Getting Exception at this Line
}
Run Code Online (Sandbox Code Playgroud)
例外: - 队列不存在或您没有足够的权限来执行操作.
此外,我无法在"计算机管理"下打开"消息队列"的安全选项卡.请参见附件截图.

我尝试在私人手动下创建消息队列,系统允许我这样做.见下文

下面是mmc跨度.

我有一个C#Publisher-Subscriber项目,打算MSMQ service在Windows中使用。该代码是在中开发的.Net Framework 4。我想在中运行它.Net Core。但是我得到了错误
“类型或名称空间名称“消息传递”在名称空间系统中不存在”。
.Net Core是否支持MSMQ?
.Net Core是否具有一个System.Messaging.dll似乎缺少的对应项?
我必须在同一域中的两个服务器之间创建MSMQ消息传递机制,SenderServer(MS Server 2012)和ReceiverServer(MS Server 2008 R2).
我在ReceiverServer中 创建了一个私有的事务性队列.\private$\receiver,我向系统和管理员提供了接收(和查看)消息权限.
然后,我创建了一个客户端应用程序,使用以下代码创建消息并将消息转发到队列:
MessageQueue queue = new queue("FormatName:Direct=OS:ReceiverServer\private$\receiver");
Message message = new Message();
message.Body = "myMessage";
using (MessageQueueTransaction tx = new MessageQueueTransaction())
{
tx.Begin();
queue.Send(message, "myLabel", tx);
tx.Commit();
}
Run Code Online (Sandbox Code Playgroud)
在部署应用程序之前,我在我的机器(Windows 7)上测试了它,它Direct=OS:ReceiverServer\private$\receiver使用State:Connected和正确地创建了一个传出队列Connection History:Connection is ready to transfer messages.消息被正确发送到ReceiverServer并放入\private$\receiver队列中.在End2End log该的ReceiverServer为每封邮件记录两个事件:
ID CN=msmq, CN=[mymachinename], CN=Computers, DC=[domain], DC=[other]已被放入队列ReceiverServer\private$\receiver(EventId:1)然后我使用相同的代码在SenderServer中 …