【问题标题】:How do I set the Priority on client side of MSMQ message sent to a WF Service activated via MQ如何在发送到通过 MQ 激活的 WF 服务的 MSMQ 消息的客户端设置优先级
【发布时间】:2012-03-26 20:33:08
【问题描述】:

我有一个 WCF 激活的工作流服务 (XAMLX) 设置(使用 WorkflowServiceHost 托管)。

此 WCF WebService 具有“NetMsMqBinding”绑定和基于 net.msmq 的端点,客户端使用该端点来安排操作。

在客户端,我使用 Visual Studio 生成代理存根以与此 WCF 服务进行通信。一切正常,我可以看到消息出现在服务器上的(日志式)MQ 中,WCF 从队列中提取消息以根据消息激活配置的工作流。

我需要控制发送到 MQ 的消息的优先级,以便某些 WCF 客户端可以优先处理其工作流。

似乎 NetMsMqBinding 并不真正支持 MQ 消息优先级。它是否正确?如果是这样,我该如何实现/模拟呢?我可以使用 MQ 触发器根据某些标志更改消息的优先级吗?

【问题讨论】:

    标签: wcf workflow-foundation-4 msmq netmsmqbinding msmq-wcf


    【解决方案1】:

    发布我的解决方案,以防有人需要解决这个问题

    NetMSMQBinding 不支持从客户端设置消息优先级,所以我使用了错误的绑定。更强大的MsMqIntegrationBinding 才是正确的选择。

    客户端: 在客户端,只需创建一个System.Messaging.Message 对象,设置优先级并将其放入指向目标MQ 的MessageQueue.MessageQueue 对象中。

    服务器端: WorkflowService 托管 WCF 项目需要 web.config 中的以下 endpointBinding:


    <endpoint address="msmq.formatname:DIRECT=OS:.\private$\MyWebService/MyProcessingService.xamlx" binding="msmqIntegrationBinding" bindingConfiguration="MyMsMqIntegrationBinding" contract="IMyProcessingService" name="MqIntegrationBindingEndPoint" />

    (地址假设 MQ 服务在 WCF 托管的本地)

    <bindings> <!--We use msmqIntegrationBinding instead of netMsmqBinding since we want to control priority of MQ messages being dropped in the queue and that is not supported in netMsmq --> <msmqIntegrationBinding> <binding name="MyMsMqIntegrationBinding" exactlyOnce="false"> <security mode="None" /> </binding> </msmqIntegrationBinding>


    从 MQ 接收 MsmqMessage 并对其进行处理的方法是通过在 XAMLX 中删除“接收”活动并选择 Message 作为内容定义 MessageType 为 System.ServiceModel.MsmqIntegrationMessage&lt;YourTypeGoesHere&gt; 现在您将可以访问此 @987654330 @来自您的ActivityContext,您可以在其中检索消息中发送的值。

    这是一种非常有用且强大的方式来构建一个可扩展的、具有优先级控制的基于 MQ+WCF+WF 的 Web 服务

    【讨论】:

    • 没有 System.ServiceModel.MsmqIntegrationMessage 这样的东西。您是说 System.ServiceModel.MsmqIntegration.MsmqMessage 吗?
    【解决方案2】:

    这些是事务性消息吗?如果是这样,您根本无法更改优先级。

    消息是不可变的,因此您无法更改已发送的非事务性消息的优先级。

    干杯
    约翰·布雷克韦尔

    【讨论】:

    • 这些不是事务性消息。我想在将消息发送到接收队列之前从客户端理想地设置消息的优先级。
    • 您只能在发送应用程序的代码中设置消息的优先级。不幸的是,我不是 WCF 用户,所以不确定在哪里设置。
    • 是的,这也是我想设置它的地方,但 netMsmqBinding 透明地将 WCF Soap 消息转换为 MSMQ 消息,反之亦然,并且不给我回电来控制消息属性。此外,我正在查看旧版 MSMQIntegrationBinding,但在新的工作流服务范式 AFAIK 中不太支持使用它
    猜你喜欢
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 2012-11-05
    • 2019-03-27
    • 2020-09-15
    相关资源
    最近更新 更多