none
How to pause a WCF queue? RRS feed

  • Question

  • When posting this question on how to implement IQueueControl to Pause a Queue previously, I focused on the the additional WCF interface to allow the client to communicate to the WCF server that the WCF queue should be paused.

    Quick review: I have used

    <serviceThrottling maxConcurrentCalls="1" maxConcurrentInstances="1" maxConcurrentSessions="1"/>

    to implement an WCF queue and my I have a function "shellCommand" that receives strings to execute with CMD.EXE and it is working great except that I have not implemented this pause feature. Lets supposed I implement the additional interface defined in the link above and the client used HttpDual and calls the Pause function on my WCF server/service. What does this pause function do so that WCF will not remove the next entry from the WCF queue and call my function ShellCommand?

    And of course I will want to implement the resume queue function as well so the shellCommand function will be called again with the oldest entry from the queue.

    Thanks

    Siegfried


    siegfried heintze

    Thursday, February 23, 2017 8:03 PM

Answers

  • Hi Siegfried,

    >> So help me understand how to implement WSDualHttpBinding endpoints that implement interfaces like IQueueControl

    There is no need to implement WSDualHttpBinding, I think you could use a new service to start and stop current msmq service.

    >> how do I implement the pause and resume functions?

    In my option, the only way is to open and close the host in another Service.

    >> How would they get that host object reference?

    For this purpose, I think you need to define the host as a global variable in the self-host application.

    Here is a simple demo under console application:

     //WCF Self host application to host two service.
    namespace WCFConsoleSelfHost
    {
        class Program
        {
            //global Service Host
            public static ServiceHost host;
            static void Main(string[] args)
            {
                host = new ServiceHost(typeof(WCFTest));
                StartStopServiceFun();
                Console.ReadLine();
            }  
        }
    }
    //Start and Stop Service
    namespace WCFConsoleSelfHost
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "StartStopService" in both code and config file together.
        public class StartStopService : IStartStopService
        {
            public string StartService()
            {
                try
                {
                    Program.host.Open();
                    Console.WriteLine("web service is open");
                    return "web service is open";
                }
                catch (Exception ex)
                {
                    //if you close the host, you need to initialize the host
                    Program.host = new ServiceHost(typeof(WCFTest));
                    Program.host.Open();
                    return "web service is open";
                }
            }
    
            public string StopService()
            {
                Program.host.Close();
                return "web service is stop";
            }
        }
    }

    One more option, to open and close a host in other service might be complex when accessing the host object. I think you could host msmq service in windows service, and then create a new wcf service to start and stop the windows service.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, February 28, 2017 5:46 AM

All replies

  • Hi Siegfried,

    >> What does this pause function do so that WCF will not remove the next entry from the WCF queue and call my function ShellCommand?

    Did you host WCF in self-host? If you stop the WCF Service, will the message in Queue disappear? If you restart WCF Service again, will WCF Service continues to process message in Queue?

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 24, 2017 7:32 AM
  • When I run in the debugger, Visual Studio runs that little hosting program automatically -- I don't remember what it is called but it pops up a little GUI.

    I also have a C# Main program that hosts it as well for production.

    (Much to my dismay, when my host program exists, it does not kill the child CMD.EXE it starts with system.Diagnostics.process.start. I guess I will have to write the code to retrieve the PID and call some function to kill the child process when the host program is exiting. This is probably a topic that is more appropriate for a different form, however).

    Yes, when I restart to the C# main hosting program, it grabs a new entry from the WCF queue which is apparently storing them somewhere on disk (I found it and looked at it once, I cannot remember the name of the file WCF uses, can you?). I need to add a button to my GUI client to clear out the queue because having those bogus entries in the WCF queue can be a problem sometimes.

    Thanks

    Siegfried


    siegfried heintze

    Friday, February 24, 2017 6:45 PM
  • Hi Siegfried,

    Could you achieve pausing a WCF queue by stopping C# main hosting program?

    >> I also have a C# Main program that hosts it as well for production.

    Based on this, it seems you host your WCF in C# main program, I assume it is self-host.

    >> when I restart to the C# main hosting program, it grabs a new entry from the WCF queue which is apparently storing them somewhere on disk

    Is this new entry which has not been processed? If so, if you want to pause a WCF queue, I think you just need to stop the C# main hosting program.

    >> (I found it and looked at it once, I cannot remember the name of the file WCF uses, can you?).

    For checking queue message, I think you could follow Computer Management(Local)->Services and Applications->Message Queueing->Private Queues.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 27, 2017 3:13 AM
  • Well I would like to implement and host another interface, perhaps with HttpDual with the same main program.

    This second interface would be called IQueueControl and would have functions like pause and resume. I would use the two way communication feature of the HttpDual protocol to let the client know when a queue entry is done executing and another new queue entry was been removed from the queue.

    I would not want to stop the main hosting program because it would not be able to respond to the resume request.

    So what I would like is to use the client to call the pause function and have the host for the WCF continue to execute so that when the current queue entry is complete, WCF does not grab a new entry from the queue but does call the client back to indicate that the current entry has completed and the queue is paused.

    For this functionality the hosting program would have to continue execution... Correct?

    Thanks

    Siegfried


    siegfried heintze

    Monday, February 27, 2017 6:10 AM
  • Hi Siegfried,

    >> I would not want to stop the main hosting program because it would not be able to respond to the resume request.

    There is no need to stop hosting program, you could close the ServiceHost. Something like below:

              //host wcf service
                ServiceHost host = new ServiceHost(typeof(WCFInCode));
                host.Open();
                host.Close();

    For your current way, how will you implement functions like pause and resume in IQueueControl? If you could achieve this, the service will not be able to respond to resume request if you pause the WCF Service either.

    If you mean create two service one is to pause and resume service and another is to msmq communication, theoretically it is possible, but I assume it may produce issue related with permission to open a service from another service.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 27, 2017 9:00 AM
  • Hmmm.... OK! That is not the answer I expected!

    So help me understand how to implement WSDualHttpBinding endpoints that implement interfaces like IQueueControl { void Pause(); void Resume(); void Register(String name) } and IQueueControlCallback { void NotifyRegistration(string Name); void NotifyJobCompletion(string Name); }

    My first impulse would be to use multiple interface inheritance and implement all the functions (except the notify functions) in my existing class that implements NetMSMQBinding functions like executeCommand  (is this even possible?). However, then my client could not call resume as you pointed out.

    So how about I create a new Visual Studio Child Project (with its own app.config) to define the Dual interfaces and implement them in a separate WCF service. Then I would enhance my existing host program to call hostDual.open() and HostDual.close()? I believe this is your suggestion.

    OK, so then how do I implement the pause and resume functions? Somehow the implementation of these functions would have to have access to the original host object for the NetMsmqBinding that implements the Queue so they could call the close and open functions. How would they get that host object reference?

    Thanks

    Siegfried


    siegfried heintze


    • Edited by siegfried_ Monday, February 27, 2017 10:42 PM
    Monday, February 27, 2017 10:39 PM
  • Hi Siegfried,

    >> So help me understand how to implement WSDualHttpBinding endpoints that implement interfaces like IQueueControl

    There is no need to implement WSDualHttpBinding, I think you could use a new service to start and stop current msmq service.

    >> how do I implement the pause and resume functions?

    In my option, the only way is to open and close the host in another Service.

    >> How would they get that host object reference?

    For this purpose, I think you need to define the host as a global variable in the self-host application.

    Here is a simple demo under console application:

     //WCF Self host application to host two service.
    namespace WCFConsoleSelfHost
    {
        class Program
        {
            //global Service Host
            public static ServiceHost host;
            static void Main(string[] args)
            {
                host = new ServiceHost(typeof(WCFTest));
                StartStopServiceFun();
                Console.ReadLine();
            }  
        }
    }
    //Start and Stop Service
    namespace WCFConsoleSelfHost
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "StartStopService" in both code and config file together.
        public class StartStopService : IStartStopService
        {
            public string StartService()
            {
                try
                {
                    Program.host.Open();
                    Console.WriteLine("web service is open");
                    return "web service is open";
                }
                catch (Exception ex)
                {
                    //if you close the host, you need to initialize the host
                    Program.host = new ServiceHost(typeof(WCFTest));
                    Program.host.Open();
                    return "web service is open";
                }
            }
    
            public string StopService()
            {
                Program.host.Close();
                return "web service is stop";
            }
        }
    }

    One more option, to open and close a host in other service might be complex when accessing the host object. I think you could host msmq service in windows service, and then create a new wcf service to start and stop the windows service.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, February 28, 2017 5:46 AM
  • Please confirm that I am understanding you:

    So I have my old existing MSMQ/WCF that is started with a little host main program.

    Now I will create a new WSHTTP/WCF called PauseResume that will implement functions pause and resume and this will replace the existing main host program.

    Then I will create a new main host program to host PauseResume (and PauseResume will effectively host the MSMQ/WCF).

    Wow! Clever. Did I get it right? This sounds simpler than the second option (and I don't see any advantages to windows service).

    Can I assume that that when WCF removes an entry from a MSMQ queue that this is atomic and I won't corrupt the internal MSMQ queue by stopping at an in-opportune time?

    Thanks

    Siegfried


    siegfried heintze

    Thursday, March 2, 2017 9:46 PM
  • Hi,

    >>Did I get it right?

    Yes, you are right.

    >>Can I assume that that when WCF removes an entry from a MSMQ queue that this is atomic and I won't corrupt the internal MSMQ queue by stopping at an in-opportune time?

    I agree with you.

    Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 3, 2017 3:09 AM