现在的位置: 首页 > 综合 > 正文

msmq两个网域之间消息传输与接收测试总结

2018年05月05日 ⁄ 综合 ⁄ 共 3213字 ⁄ 字号 评论关闭

近一段时间我负责的一个项目,在做数据传递时,选择了msmq的作为传输平台,由于网络环境和应用系统平台的复杂性,针对msmq的解决方案,我做了大量的测试,也遇到了很多的问题,其中有面对不同windows操作系统时的,也有面对不同的网络环境的(网通、电信、铁通等等),也有和传输报文的内容及大小相关的,也有和msmq server的安全和权限设定相关的,由于ms的mq是免费产品,所以能得到的技术支持有限,不得不自己边摸索边总结,其中的苦闷可想而知。为了让以后使用msmq的朋友少走些弯路,我把自己的一些碰到的一些问题和解决方法公布出来,供大家参考,由于时间有限,该文在后面慢慢完善。
问题描述:

  1,应用场景:2台域控制器window2003 Server AB之间用msmq3.0做消息传递.2server都打了最新的补丁包,

 

     msmq安全属性给everyone群组最高权限,域控制安全策略网络访问设定让everynone权限应用于匿名用户。

              AMSMQ Server的服务器,A服务器上建有公共队列A001;

              Bmsmq的客户端,部署有发送和接收应用程序。

  2,应用过程

              B发送应用程序向A上的消息队列A001发送消息,在A的消息队列A001中看到从B发送来的消息,表明消息发送成功;

       B接收应用程远程读取A上消息队列A001中的消息,出现异常。

  3,应用程序代码

        //消息发送

 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());

 }

4,接收消息的异常

   /*

 ---------------------------

 

 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

    */

5,问题

     我在做测试的过程中,如果B为独立服务器(没有装AD,其操作系统为window2003,window
xp,window2000
接收消息都没有问题,但是在域

控制器作为客户端接收消息的服务器时就出现了如上问题,原因是什么?如何解决这个问题?在域控制器中msmq默认的远程读取帐户是什么?

6,总结
 

1.       MQ不能用HTTP方式接收(只能用HTTP方式发送)

2.       在不同网域接收MQ时,必须打开everynoneguest账号(可以试试)。

3.       建议不要用client去接收MQ讯息,这样会存在很多安全隐患,而且讯息接收不稳定。

MQ SERVER 有可能会“瀑满”,也就是说,如果讯息来不及“取走”的话,会丢失。

7,向微软确认后,微软的回复

Here are eleven programming guidelines for Writing Better MSMQ Applications You should follow them when writing an MSMQ application.

  • Do only local receives.
  • Avoid functions that query the Message Queue Information Store (MQIS).
  • Implement timeouts.
  • Understand the limits of asynchronous notification.
  • Know when and where to use transactions.
  • Know when to use persistable COM objects.
  • Understand what security context to use.
  • Implement smart queue usage.
  • Request acknowledgements or nonacknowledgements.
  • Remember case sensitivity.
  • Test your application with a full reboot while offline.

 

#3楼[楼主]
  

公共队列必须安装了活动目录后才能使用,默认组模式下只能使用私有队列。

抱歉!评论已关闭.