Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Checking for an empty queue in Service Broker

Posted on 2010-01-11
Medium Priority
Last Modified: 2012-06-22
I need to write code that pulls from a queue until the queue is empty.  The name of my pulling procedure is MsgIncoming_Queue_Receive and it works fine when called one at a time.

What I need help with is the condition of the loop.  How can I test outside the service broker system whether the queue is empty?  In fact this is supposed to be done within coldFusion code.  

The psuedo code is shown below:

while (! emptyQueue) {
Question by:onaled777

Author Comment

ID: 26284578
I am assuming that probably sql service broker has an interface of some sorts that would make this easier that checking the count(*) from the queue....
LVL 10

Accepted Solution

lof earned 1000 total points
ID: 26332713
Service broker queues are implemented as hidden tables so you cannot use standard T-SQL queries to update them but with each queue there is a read-only view associated so you can use standard SELECT statement to see what is in the queue.

so to see how many messages you have in the queue all you have to do is:

select count(*) from yourQueueNameHere

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Loops Section Overview
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question