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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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