msmq消息队列使用及测试总结

该博客记录了MSMQ消息发送与接收的测试情况,测试环境涉及多种Windows操作系统。给出了消息发送和接收的测试代码,运行结果显示不同操作系统客户端在消息接收上存在差异。最后提出了MSMQ远程接收消息时客户端和服务器端配置、原因原理以及默认帐户等疑问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//测试环境说明
//1,发送与接收应用程序客户端:window2003 server, window2000 server,window xp;
//2,msmq server :window2003 server +活动目录(已经为msmq消息队列的everynone帐户设置了所有权限)

//消息发送测试代码
try
   {
    System.Messaging.MessageQueue Queue;
    Queue = new System.Messaging.MessageQueue(@"FormatName:DIRECT=TCP:172.26.230.2\ptest1");
    
    System.Messaging.Message Msg;
    Msg = new System.Messaging.Message();
    Msg.Formatter =new System.Messaging.BinaryMessageFormatter();
    Msg.Body="Testing 3 times";
    Queue.Send(Msg);
   }
   catch(Exception ex)
   {
    System.Windows.Forms.MessageBox.Show(ex.ToString());
   }  

//消息接收测试代码
try
   {
    System.Messaging.MessageQueue mq = new System.Messaging.MessageQueue(@"FormatName:DIRECT=tcp:172.26.230.2\ptest1");

    // Set the queue'ss formatter to decode Point objects

    mq.Formatter = new System.Messaging.BinaryMessageFormatter();
    System.Messaging.Trustee trustee=new System.Messaging.Trustee();
    
    System.Messaging.Message msg = mq.Peek ( new TimeSpan(10000)) ;


    // Convert received message to object that we think was sent

    string pt = (string) msg.Body ;

    // Display it to the user
    
    MessageBox.Show (pt) ;
   }
   catch(Exception ex)
   {
    MessageBox.Show(ex.ToString());
   }


//运行结果说明
//1, 所有操作系统类型的客户端向远程msmq服务器发送消息成功
//2,window2000环境下从远程服务器接收消息成功
//   window xp客户端接收失败
//   window 2003(未安装活动目录)部分客户端接收成功,部分失败
//   window 2003(安装活动目录)所有客户端接收消息失败    
//3,异常讯息如下:
/*
---------------------------

System.Messaging.MessageQueueException

   at System.Messaging.MQCacheableInfo.get_ReadHandle()

   at System.Messaging.MessageQueue.StaleSafeReceiveMessage(UInt32 timeout, Int32 action, MQPROPS properties, NativeOverlapped* overlapped, ReceiveCallback receiveCallback, IntPtr cursorHandle, IntPtr transaction)

   at System.Messaging.MessageQueue.ReceiveCurrent(TimeSpan timeout, Int32 action, IntPtr cursor, MessagePropertyFilter filter, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)

   at System.Messaging.MessageQueue.Peek(TimeSpan timeout)

   at InternetQueueingRecipient.Form1.button2_Click(Object sender, EventArgs e) in c:\msmqandnet\msmqandnet\internetqueuing\internetqueueingrecipient\form1.cs:line 294
*/

疑问:msmq3.0远程接收消息时,客户端要做何种配置,服务器端要做何种配置?原因与原理?msmq远程读取消息的使用的默认帐户为
什么?

转载于:https://www.cnblogs.com/billqi/archive/2005/12/23/303539.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值