WCF Service Listener for MSMQ - Message Waiting

I created a WCF service that listens for private MSMQ for jobs. I turned off my service so that it will only process one job at a time (maxConcurrentInstances = 1). The problem is that when you send two messages and check the queue through the computer management console, it is empty. I expect there will be one pending message. When I send three messages, I will see one waiting message in MSMQ. From reading the MSDN, it seems that ServiceHost holds the next job in memory until the current job is completed, but I cannot find a way to disable it so that it does not hold the message in memory. Does anyone know a way to do this so that ServiceHost does not hold the waiting message in memory and leaves it in the queue? Thanks!

<configuration> <system.serviceModel> <services> <service name="MyService" behaviorConfiguration="DefaultServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/MyService/"/> </baseAddresses> </host> <endpoint address="net.msmq://localhost/private/MyService" binding="netMsmqBinding" bindingConfiguration="MsmqBindingNoSecurity" contract="IMyService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="DefaultServiceBehavior"> <serviceMetadata httpGetEnabled="True"/> <serviceThrottling maxConcurrentCalls="1" maxConcurrentSessions="1" maxConcurrentInstances="1" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <netMsmqBinding> <binding name="MsmqBindingNoSecurity" useActiveDirectory="false" exactlyOnce="false"> <security mode="None"> <transport msmqAuthenticationMode="None"/> </security> </binding> </netMsmqBinding> </bindings> </system.serviceModel> </configuration> 
+4
source share
2 answers

I also noticed this behavior in netMsmqBinding, and as far as I know, it is not addressed by the service.

This is only a problem if you do not use transactional queues, because of which a failure in your service can cause the message in memory to be permanently deleted.

If you use transactional queues, even if the message was read from an incoming queue, it is actually still in the queue (but it becomes "invisible"). If you fail in your service, the message will be reordered at that time and then processed when you return.

If you cannot use transactional ordering, then the only way you can access this is to do it from the client, which means that you check if the message was sent before another call. This can be done using System.Messaging, or I assume you can bake it in the usual way.

0
source

If you cannot use a transactional queue (for example, if you use netMessagingBinding), you can use the ReceiveContext attribute for finer-grained control. He was well explained by Juval Lowy in his book:

http://books.google.co.uk/books?id=PvNrurEhmiEC&pg=PA500&lpg=PA500&dq=ReceiveContext&source=bl&ots=ChDvHuH_Jq&sig=XHhiz2ebmXuu0QNYcBYhtlN99p4&hl=en&sa=X&ei=XgYmUo3kHOOH0AW--oHoCg&ved=0CFsQ6AEwCTgK#v=onepage&q=ReceiveContext&f=false

Also see this MSDN article to find out exactly how it can be used in the netMessagingBinding script (I know that is not directly related to your question, but the main one still persists)

http://msdn.microsoft.com/en-us/library/hh532034(VS.103).aspx

0
source

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


All Articles