none
Net.Msmq Binding Not Picking Up Messages in Queue as soon as the application pool gets recycled RRS feed

All replies

  • Hi Alessandro

    The queues can only be processed by the service if the service is started. When you recycle the appPool, the service stops and will not start until a request is made. This is why it picks up the messages when you query the service metadata page.

    Cheers

    Francois

    Thursday, April 15, 2010 8:48 AM
  • The following article is dedicated to this issue:

    http://msdn.microsoft.com/en-us/magazine/cc163357.aspx

    Thursday, April 15, 2010 7:17 PM
  • Thanks for the replies.

    @Francois: I understand that the service picks up the messages only when it is active, but in my understanding there should be some WCF plumbing in between msmq and my service that will listen on the queue and activate my service when the message comes without having to manually browse the metadata page. Am I wrong?

    @Jesse: very nice link, but I can't find anything that can help me. That is a description on how the WAS activation works and from what I can see I already did everthing that is described there. I implented the service host factory detailed in the "lifetime management" section and (as expected) the "CreateServiceHost" method is called only when I hit the service metadata page, which is my original problem (the service does not get activated automatically unless it's already awake and active)

     

     


    If this post is helpful, please mark it as such
    ________________________________________
    Alessandro Cardoso
    MVP | Microsoft Heroes | MCT
    blog: http://itaustralia.spaces.live.com
    http://cardosoalessandro.spaces.live.com
    Saturday, April 17, 2010 1:56 AM
  • There are a lot of things that can go wrong here.... this might be the culprit:

    It's important to note that the activation of MSMQ endpoints only works correctly if the queue has the same name as the .svc file (minus the machine name). That means that if your service endpoint is /server/app/service.svc, the queue name must be app/service.svc.
    In the service configuration you have to specify the name of the queue the service should listen on:
    <endpoint address="net.msmq://localhost/private/wasdemo/service.svc"
     binding="netMsmqBinding" bindingNamespace="urn:msdnmag"
     contract="IServiceMsmq" />

    Saturday, April 17, 2010 10:04 AM
  • Hi Jesse

    Yes. We know that. The Queue is corretly configured with the SAME name as I already mention :

    We created a private queue called Test/service.svc and our service endpoint is net.msmq://machinename/Test/service.svc, where machine name is the Full Qualified Domain Name of the Machine. (We a re not using localhost due the service is being called by another server )

     

     


    If this post is helpful, please mark it as such
    ________________________________________
    Alessandro Cardoso
    MVP | Microsoft Heroes | MCT
    blog: http://itaustralia.spaces.live.com
    http://cardosoalessandro.spaces.live.com
    Monday, April 19, 2010 1:26 AM
  • Hi Alessandro,

    Regarding on your scenario, the client use WCF MSMQ binding to deliver the messages, and you find that the service won't pickup the messages(in the queue) after it get recycled(unexpectedly).

    I think this behavior is possibly due to your WCF MSMQ binding is not using reliableMessaging (the msmq itself is also not a transactional queue). For transactional queue, you can deliver the message in transactional manner so that MSMQ will ensure the delivery and order of the message. Also, at WCF side, the corresponding also need to enable Transaction and reliablemessage.

    #Transacted MSMQ Binding
    http://msdn.microsoft.com/en-us/library/ms751493.aspx

    #How Your WCF Service Can Use MSMQ as a Durable Message Store
    http://www.devx.com/dotnet/Article/41482/1954


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, April 23, 2010 2:48 AM
    Moderator
  • Hi Steven,

     

    I am Alessandro's colleague, I am working with him on these net.msmq issues. 

    Our configuration includes a transactional queue called Test/Service.svc (unauthenticated, we shut down all security for the moment...does it matter?) and these attributes on the service:

    [ServiceContract]
    public interface IService
    {
      [OperationContract(IsOneWay=true)]
      void ProcessMyMessage(MyClass parameter);
    }
    
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, TransactionIsolationLevel = IsolationLevel.Serializable, TransactionTimeout = "00:03:00")]
    public class Service: IService
    {
        [OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
    	public void ProcessMyMessage(MyClass parameter)
    	{
           //Do some stuff here
    	}
    }

    The service is hosted on IIS 7.5 under an application called Test (so that the full http address of the service is http://machine/Test/Service.svc).
    In the configuration (for both client and service) we specified None for the security mode, "true" value in durable and exactlyOnce

    The Net.msmq Listener Adapter windows service is running fine under the Network Service account (the same as our application pool)

    Is there something we are missing?

    Also, can you explain how a transaction not configured properly can create this behaviour? In my understanding the process of delivering a message happens in 3 steps (I remember a nice picture of this the Juval Lowy book):

    1) Transaction 1: client delivers message to local instance of msmq. The transaction rolls back if the message does not get delivered.

    2) Transaction 2: the local instance of msmq delivers the message to the remote (service) instance of msmq. The transaction rolls back if the message does not get delivered.

    3) Transaction 3: wcf activates my service which picks up the message and process it. The transaction rolls back if the service fails to pick up the message or does not complete the transaction (for example, because of an unhandled exception).

     

    The message gets delivered to the service machine successfully, so I am assuming that steps 1 and 2 are executed correctly. If my service was not configured to handle transaction properly, wcf should still activate it and do something with it. Or at least, if it doesn't get activated at all, this should be the case even when the application pool is well alive and awake, because it should be a configuration problem. Instead, the service works great if the appPool is alive and it never gets activated when the appPool is sleeping (absolute nothing in the .svclog trace file generated by the service). Am I saying something wrong?

     

    Friday, April 23, 2010 4:24 AM
  • Hi Roberto,

    So the MSMQ you used is a transactional queue, when invoke the service operation, have you used the TransactionScope to wrapper the operation call so as to make sure a transaction is used during the operation execution. The TransactionScope can help start a transaction session and let the MSMQ integrate it underlyingly and be propagated to the service side.

    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, 
    
    options))
    
    {
    
    client.CallTransactionalOperation();
    
    }
    

    For testing, you can also first try using a WCF service which use Transaction without MSMQ based binding(use netTcp or WsHttpBinding) and make sure the transaction works and then copy the transaction related setting to MSMQ binding.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Wednesday, April 28, 2010 2:55 AM
    Moderator
  •  

    Hi,

     

    I've got exactly the same probleme.

    "when the application pool is "alive" the service picks up the messages correctly, but as soon as the application pool gets recycled (because of timeout or any other reason), the service stops picking up the messages, that just sit in the queue until the service starts again by browsing to the service webpage"

    Have you find a solution, to activate the service without manualy browse the service.

    regards

    Yann

    Thursday, May 6, 2010 9:38 AM
  • Hi

    Not yet. We are thinking in create a Windows Service to periodicaly call the service webpage or something related.

     

     


    If this post is helpful, please mark it as such
    ________________________________________
    Alessandro Cardoso
    MVP | Microsoft Heroes | MCT
    blog: http://itaustralia.spaces.live.com
    http://cardosoalessandro.spaces.live.com
    Thursday, May 6, 2010 12:45 PM
  • When the WCF service is WAS hosted, it gets activated by the "Net.Msmq listener adapter" (netmsmqactivator) service which polls the queues for new messages. The polling interval for this service is 10 minutes. Whenever you restart the netmsmqactivator service, you will notice that the messages are consumed by the WAS hosted WCF service.
    Friday, May 21, 2010 7:05 AM
  • Hi Devang

    This is not the problem

    The problem is :  the service stops picking up the messages, that just sit in the queue until the service starts again by browsing to the service webpage (http://machinename/Test/service.svc)


    If this post is helpful, please mark it as such
    ________________________________________
    Alessandro Cardoso
    MVP | Microsoft Heroes | MCT
    blog: http://itaustralia.spaces.live.com
    http://cardosoalessandro.spaces.live.com
    Monday, May 24, 2010 12:37 AM
    1. Both the IIS worker process (App Pool) and the Net.Msmq Listener service should use the same account, this account must also have Peek and Receive rights on the queue (but it’s better to just give it full control).  You can verify the account used by your web service by checking the account used by w3wp.exe in task manager
    2. Ensure that the Net.Msmq listener is running using an unrestricted token, the following command should work “sc sidtype netmsmqactivator unrestricted”
    3. Add a DWORD called “AllowNonauthenticatedRpc” to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\Parameters\security, and set it to 1

    Monday, July 12, 2010 5:14 PM
  • Hi cboucas,

     

    what you suggest looks really interesting, we definitely have done step 1 and 2, but I had never seen step 3 before, maybe that's what we are missing.

    Unfortunately, our little wcf/msmq project is on hold at the moment so I don't have time to spend on it and I won't be able to check if that was our problem. I will keep it in mind and make sure to try that out as soon as I get some time. I can't mark your answer as "the" answer yet, but I voted it as useful in the meantime.

    Thanks a lot for that

     

    Roberto

    Wednesday, July 21, 2010 11:40 PM
  • I was having the same problem after adding a 2nd application/queue to a web server.  The queue would collect the messages but would not process them, unless I manually started the service.  So, after going to the services and restarting the Net.MSMQ Listener Adapter, then resubmitting my requests, the queue and services worked correctly.

    So my questions is, does the Net.MSMQ Listener Adapter need to be restarted after adding new applications with the http;net.msmq protocols enabled before the listener knows that it should be listening to those applications?

    Thank you,

    Kevin

    Tuesday, July 27, 2010 2:48 PM
  • I have the exact same problem. Kevin, have you got any answer? MSFT guys: is this confirmed?

    Regards.

    Saturday, January 29, 2011 11:25 PM
  • I suppose one need to restart the service Net.Msmq service on making changes to IIS applications as it caches the service names, queue mapping. Net.Msmq Listner services activates the w3p process on recieving a message if you have queue name same as relative path for the service. For e.g. create a queue with name "foo/Service1.svc"  under private queues for service with Url http://machinename/foo/Service1.svc.
    Wednesday, March 2, 2011 9:45 PM
  • WOW After reading this thread I've an impression the Net.Msmq binding has a HUGE bug.
    Leonid Ganeline [BizTalk MVP] BizTalk: Adanced Interview Questions
    Tuesday, January 10, 2012 9:49 PM
    Moderator
  • We are facing the same problem, even after configuring 'Always Running',  Net.MSMQ Listener Adapter.

    please post if any solution for this.

     

    Thank you.

    Wednesday, February 1, 2012 9:16 AM
  • MSFT appear to have confirmed there is indeed a bug causing this in some cases:

    http://blogs.msdn.com/b/distributedservices/archive/2011/11/11/wcf-and-msmq-integration.aspx

    Their only solution, until .NET 4.5, seems to be to just ping the svc to keep the app pool alive.

    Tuesday, February 14, 2012 2:02 PM
  • Dear MS team,

    this issue is not resolved even with .NET 4.5

    May I know what is your stratagey for this issue? When this will get addressed?


    Venkat

    Wednesday, June 12, 2013 11:43 AM
  • We had the same problem, but finally found the solution.

    We added a Debugger.Launch() statement to our method and found that the call was indeed being made, but failing.

    We found that the Application_Start was not being called from a MSMQ request. Application_Start didn't get called until we pinged using HTTP.  This caused our problem because Ninject was being configured in the Application_Start method. To solve the problem, we removed all code from the Application_Start method and used singleton properties as shown in the following example.

            private static StandardKernel _container;
            public static StandardKernel Container
            {
                get { return _container ?? (_container = ConfigureNinject()); }
            }

            private static StandardKernel ConfigureNinject()
            {
                var kernel = new StandardKernel(new CommonModule());
                kernel.Bind<PersonalLinesWebHandler>().ToSelf();
                return kernel;
            }

    Note that the magic is in the getter.

    Hope that helps.


    Glenn Johnson

    Friday, June 28, 2013 2:28 PM
  • I could resolved this way:

    https://stackoverflow.com/questions/15379457/net-msmq-binding-not-picking-up-messages-in-queue-as-soon-as-the-application-poo/35416005#35416005

    Monday, February 15, 2016 6:05 PM
  • The solution is to configure auto-start. Then IIS will start your service immediately without waiting for the first request.

    But first you need to add Appfabric to your ISS, then you need be sure you have the "Start Mode" option in your pool advance settings.

    Note: In my windows 7 IIS7 didnt work, but in my windows server 2012 R2 IIS8 Works perfectly

    https://stackoverflow.com/questions/15379457/net-msmq-binding-not-picking-up-messages-in-queue-as-soon-as-the-application-poo/35416005#35416005

    Monday, February 15, 2016 6:10 PM
  • Possible solution is to configure auto-start. Then IIS will start your service immediately without waiting for the first request. It works for me!

    But first you need to add AppFabric to your ISS, then you need be sure you have the "Start Mode" option in your pool advance settings.

    Note: In my windows 7 IIS7 didnt work, but in my windows server 2012 R2 IIS8 Works perfectly

    https://stackoverflow.com/questions/15379457/net-msmq-binding-not-picking-up-messages-in-queue-as-soon-as-the-application-poo/35416005#35416005

    Monday, February 15, 2016 6:14 PM