转载自:http://blog.csdn.net/hoken2020856/article/details/5622860
WCF(Windows Communication Foundation) - 消息队列(MSMQ - MicroSoft Message Queue):
netMsmqBinding的binding属性配置如下:
·ExactlyOnce - 确保消息只被投递一次。只能应用于事务型队列,默认值 ture
·Durable - 消息是否需要持久化。默认值 enabled,如果设置为disable,当MSMQ服务重启后,先前保存在MSMQ中的消息将会丢失
·TimeToLive - 消息过期并且从原有的队列移动到死信队列的时间。默认值 1.00:00:00 (1天)
·ReceiveRetryCount - 配置队列管理器在一定重试间隔中,尝试重新投递消息的次数,也就是将消息传输到重试队列前尝试发送该消息的最大次数(每隔RetryCycleDelay的时间重试ReceiveRetryCount次)。缺省值 5
·MaxRetryCycles - 配置队列管理器重新投递消息的重试间隔数(执行RetryCycleDelay的次数),也就是重试最大周期数。缺省值 2
·RetryCycleDelay - 表示两次重试之间的间隔时间,也就是重试周期之间的延迟。缺省值 00:30:00
·ReceiveErrorHandling - 指定如何处理错误的消息。Fault、Drop、Reject或Move(具体说明查MSDN)
·DeadLetterQueue - 指定所使用的死信队列的类型。None、System、或Custom(具体说明查MSDN)
·CustomDeadLetterQueue - 本地自定义死信队列的URI
示例
1、服务
IMSMQ.cs
MSMQ.cs
2、宿主
MSMQ.cs
App.config
3、客户端
MSMQ.cs
App.config
运行结果:
客户端调用时,如果没有启动服务端,那么消息会进入到消息队列中。等到服务端启动后,会执行消息队列中的所有消息。
MSMQ 防火墙 端口 配置
The table below describes the ports used by Message Queuing:
Port | Purpose | Applicable Version |
TCP 135 | Dynamic RPC port typically assigned by RPC for handshaking with an independent client or with an RPC server for the Message Queuing server to determine the fixed ports. | MSMQ 5.0 MSMQ 4.0 MSMQ 3.0 MSMQ 2.0 MSMQ 1.0 |
TCP 389 | Reserved port used by independent clients and Message Queuing servers to make MQIS requests directly to Active Directory using LDAP. | MSMQ 5.0 MSMQ 4.0 MSMQ 3.0 |
TCP 1801 | Message Queuing (including HTTP messaging) message traffic and internal session management traffic between Queue Managers. | MSMQ 5.0 MSMQ 4.0 MSMQ 3.0 MSMQ 2.0 MSMQ 1.0 |
UDP 1801 | Reserved port used by the Message Queuing independent client to multicast a server discovery broadcast. | MSMQ 5.0 MSMQ 4.0 MSMQ 3.0 MSMQ 2.0 MSMQ 1.0 |
TCP 2101* | Message Queuing listens on this port on the Domain Controller for RPC-based MQIS and Active Directory lookups. | MSMQ 5.0 MSMQ 4.0 MSMQ 3.0 MSMQ 2.0 MSMQ 1.0 |
TCP 2103* TCP 2105* | On these two ports, Message Queuing independent clients and servers listen for RPC-based remote reads of their public queues and private queues. The dependent client also uses these two ports to communicate with its server for send and for receive. | MSMQ 5.0 MSMQ 4.0 MSMQ 3.0 MSMQ 2.0 MSMQ 1.0 |
UDP 3527 | Reserved port used for the internal "ping" mechanism for Message Queuing. Note On Message Queuing 4.0 and later, UDP port 3527 is no longer used by default. For more information on this change, visit the following links: Security Enhancements that Affect the Default Behavior of Message Queuing MSMQ’s internal ping mechanism over port 3527 | MSMQ 3.0 MSMQ 2.0 MSMQ 1.0 |
* These port numbers may be incremented by 11 if the initial choice of RPC port is being used when Message Queuing initializes. A connecting QM queries port 135 to discover the 2 xxx ports.
The table below lists the MSMQ version by operating system:
Operating System | Message Queuing Version |
Windows Server 2008 R2 Windows 7 | MSMQ 5.0 |
Windows Server 2008 Windows Vista | MSMQ 4.0 |
Windows Server 2003 R2 Windows Server 2003 Windows XP Professional | MSMQ 3.0 |
Windows Server 2000 Windows Professional 2000 | MSMQ 2.0 |
Windows NT 4.0 | MSMQ 1.0 |