开发者

Using msmq and wcf

I had posted this question earlier post ?

Started reading up on wcf and msmq.

My first question would be - say i have a 100 messages in the queue , how would i tell开发者_如何转开发 my service to start working on each message asynchronously so that it is working on multiple messages at the same time. is this even possible or is it always a synchronous operation?

Update: Let's say my system is as such that i have remote locations/servers where files are uploaded too. All my processing happens at a central location. Would msmq and wcf be leveraged wherein all files from remote locations are copied to central location. The messages could be fed by an application monitoring a DB and once it determines that a file should be copied over, it feeds a message which the wcf service receives and copies the file from remote to central location.

As this is a dedicated network, the file will be accessible via unc paths. I know my clients will be inclined to do this at some point and trying to determine if this is feasible given volume of file and requirements of simultaneous file copies.

I suggested BITS but the client is not comfortable with BITS due to politics with their IT dept.


The WCF server side code will be controlled by the service throttling settings in config. By default, for each request (message in the queue), an instance of the service class will be created to handle the message.

The server-side WCF ServiceHost will handle this management for you - no special handling on your side needed.

The service throttling can be controlled by the serviceThrottling behavior. Check out this excellent blog post by Dan Rigsby on the details of how to setup the throttling in config.

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="throttled">
                <serviceThrottling
                    maxConcurrentCalls="16"
                    maxConcurrentInstances="2147483647"
                    maxConcurrentSessions="10"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

The most important settings will be the maxConcurrentCalls - this defines how many concurrent calls will be handled by your WCF service.

You should also check out this blog post here that shows how to use MSMQ+WCF and how that contrasts to straight MSMQ and WCF-over-HTTP. Excellent intro, excellent video.


The Queue (as the name suggests) contains a linear queue of objects. You have to take one off before you can take the next.

You can create a receiveCompleted event handler to take an object off the queue and pass it along to some other component for processing

qq.ReceiveCompleted += new ReceiveCompletedEventHandler(qq_ReceiveCompleted);
qq.BeginReceive();

static void qq_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
   //DO SOMETHING WITH e.Message.Body e.g. Start a seperate thread which processes the object.

   // Listen for the next message.
   queue.BeginReceive();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜