Stephen Kaufman's WebLog

Look who's BizTalk'in - Notes on all things integration

Processing FIFO MSMQ Messages using WCF

Processing FIFO MSMQ Messages using WCF

  • Comments 4
 

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. 

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

  • In my previous entry on Processing FIFO MSMQ Messages using WCF I said that I would cover processing

  • In my previous entry on Processing FIFO MSMQ Messages using WCF I said that I would cover processing

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

Page 1 of 1 (4 items)