Using msmq and wcf

I posted this question before post?

Reading began on wcf and msmq.

My first question: let's say I have 100 messages in the queue, how can I say that my service starts working on each message asynchronously, so that it works with several messages at the same time. is it even possible or is it always a synchronous operation?

Update: Say my system is such that I have remote locations / servers where files are also uploaded. All my processing takes place in a central place. Msmq and wcf will be used, in which all files from remote locations are copied to a central location. Messages can be submitted by the application that controls the database, and after it determines that the file should be copied, it transmits the message that the wcf service receives and copies the file from a remote to a central location.

Since this is a dedicated network, the file will be accessible through non-empty paths. I know that my clients will be inclined to do this at some point and try to determine if this is possible with a given file size and requirements for simultaneous copies of files.

I suggested BITS, but the client does not like BITS because of the policy with their IT department.

+3
source share
2 answers

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 process the message.

The server ServiceHost-side WCF server will handle this control for you - no special processing is required on your side.

Service regulation can be driven by behavior serviceThrottling. Check out this great Dan Rigsby blog post on the details of throttling settings in config.

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

The most important parameters will be maxConcurrentCalls- this determines how many simultaneous calls will be processed by your WCF service.

, , MSMQ + WCF MSMQ WCF- -HTTP. , .

+3

( ) . , .

receiveCompleted,

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();
}
+1

Source: https://habr.com/ru/post/1739691/


All Articles