다음을 통해 공유


Processing FIFO MSMQ Messages using WCF

 

I have been having fun working on the middle tier of an application which is using BizTalk, Windows Workflow, MSMQ and the Windows Communication Framework.

 

One of the requirements is to processes messages we receive from a legacy system through MSMQ in FIFO order. 

 

We used WCF to communicate with MSMQ and used the msmqIntegrationBinding binding since the legacy application was placing the messages on the queue.

 

The FIFO processing seemed to be little more difficult to iron out.  It turns out that by default a service's InstanceContextMode is PerSession.  If the channel is a datagram then the IntanceContextMode degrades to PerCall.  So what happens is that the WCF runtime will create a new service instance for each available request/message up to the MaxConcurrentCalls/MaxConcurrentInstance setting utilizing multiple threads.  This was not going to provide my FIFO processing.

 

So, to set WCF to only pull and process one message at a time you need to set the service's InstanceContextMode to Single along with setting the ConcurrencyMode to single.  The following code shows these settings:

 

        [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,

        ConcurrencyMode = ConcurrencyMode.Single,

         )]

    public class MSMQEventService : IMSMQEventInterface, IDisposable

    {

 

Once these settings are set you will achieve FIFO processing and WCF will only utilize a single thread and will process one message at a time from the single queue.

 

My next entry will cover processing multiple queues and processing each queue in FIFO order.

Comments

  • Anonymous
    September 17, 2007
    Ah, the StarBucks is starting to kick in... BizTalk/WCF/MSMQ/WF/CSD/Orcas Neudesic's own David Pallmann

  • Anonymous
    February 20, 2008
    In my previous entry on Processing FIFO MSMQ Messages using WCF I said that I would cover processing

  • Anonymous
    February 20, 2008
    In my previous entry on Processing FIFO MSMQ Messages using WCF I said that I would cover processing

  • Anonymous
    August 20, 2008
    In two of my previous posts I talked about processing MSMQ messages in FIFO order with WCF. The way that