wcfworkflow-foundation-4msmqnetmsmqbindingmsmq-wcf

How do I set the Priority on client side of MSMQ message sent to a WF Service activated via MQ


I have a WCF activated WorkFlow Service (XAMLX) setup (hosted using WorkflowServiceHost).

This WCF WebService has a 'NetMsMqBinding' binding and a net.msmq based endpoint which is used by clients to schedule operations.

On the client side, I've used Visual Studio to generate the proxy stub to communicate to this WCF service. Everything is working fine and I can see the messages appearing in my (journaled) MQ on the server and WCF picking up messages from the queue to activate the configured workflow based on the message.

I need to control the priority of the messages being sent to MQ so that certain WCF clients can get prioritized processing of their workflows.

It seems NetMsMqBinding doesn't really support MQ message prioritization. Is this correct? If so, how can I achieve/simulate this? Can I use MQ Triggers to change priority of messages based on some flags?


Solution

  • Posting my solution, in case someone needs to figure this out

    NetMSMQBinding does not support setting message priority from the client side so I was using the wrong binding. The more powerful MsMqIntegrationBinding is the right way to go.

    Client side: From the client side, one needs to simply create a System.Messaging.Message object, set the priority and drop it in the MessageQueue.MessageQueue object which points to the destination MQ.

    Server side: The WorkflowService hosting WCF project needs the following endpointBinding in the web.config:


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

    (the address is assuming MQ service is local to the WCF hosted)

    <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>


    The way to receive the MsmqMessage from the MQ and process it is by dropping a "Receive" activity in the XAMLX and choosing Message as the Content definition MessageType as System.ServiceModel.MsmqIntegrationMessage<YourTypeGoesHere> Now you'll have access to this MsmqMessage<yourType> from your ActivityContext where you can retrieve the value sent in the message.

    This is a very useful and powerful way to build a scalable, throttled with priority control MQ+WCF+WF based web service