多個 WCF 服務/客戶端需共用同一個 MSMQ 消息隊列,如何配置?
多個 WCF 端點共用一個 MSMQ 隊列完全可行,配置與單端點無異。 關鍵在於:
net.msmq 地址指向同一隊列(如 net.msmq://localhost/private/myqueue)。netMsmqBinding)。<system.serviceModel>
<services>
<service name="MyService">
<endpoint address="net.msmq://localhost/private/sharedqueue"
binding="netMsmqBinding"
contract="IMyContract" />
</service>
</services>
</system.serviceModel>
<system.serviceModel>
<client>
<endpoint name="MsmqEndpoint"
address="net.msmq://localhost/private/sharedqueue"
binding="netMsmqBinding"
contract="IMyContract" />
</client>
</system.serviceModel>
exactlyOnce="true"(默認),發送/接收均在事務中。Receive 同一隊列,MSMQ 保證消息只被一個實例取走(競爭消費模式)。retryCycleDelay、maxRetryCycles 等處理失敗消息。ReceiveMessage/SendMessage 權限。詳細配置可參考:WCF MSMQ 多端點共用隊列實戰
無特殊配置差異,**地址指向同一隊列即可**。MSMQ 本身支持多發送者、多接收者並發訪問同一隊列,WCF 透傳此能力。