Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to programatically check if NServiceBus has finished processing all messages
    text
    copied!<p>As part of an effort to automate starting/stopping some of our NServiceBus services, I'd like to know when a service has finished processing all the messages in it's input queue.</p> <p>The problem is that, while the NServiceBus service is running, <strong>my C# code is reporting one less message than is actually there</strong>. So it thinks that the queue is empty when there is still one message left. If the service is stopped, it reports the "correct" number of messages. This is confusing because, when I inspect the queues myself using the Private Queues view in the Computer Management application, it displays the "correct" number.</p> <p>I'm using a variant of the following C# code to find the message count:</p> <pre><code>var queue = new MessageQueue(path); return queue.GetAllMessages().Length; </code></pre> <p>I know this will perform horribly when there are many messages. The queues I'm inspecting should only ever have a handful of messages at a time.</p> <p>I have looked at <a href="https://stackoverflow.com/questions/3869022">other</a> <a href="https://stackoverflow.com/questions/3686312">related</a> <a href="https://stackoverflow.com/questions/10757333">questions</a>, but haven't found the help I need.</p> <p>Any insight or suggestions would be appreciated!</p> <p><strong>Update:</strong> I should have mentioned that this service is behind a Distributor, which is shut down before trying to shut down this service. So I have confidence that new messages will not be added to the service's input queue.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload