Back To Basics: Service Broker Queues

Published On: 2008-06-05By:

The service broker queue is where the messages are stored after they are delivered, but before they are processed.  They are kind of like tables as you insert data into them (sending the message) and you view the data in them (receiving the message).  While tables can have triggers, queues can have what are called activated procedures.  If a queue has an activated procedure defined when the message arrives in the queue the queue runs the procedure.  No data is passed to the procedure, that procedure still needs to do a receive against the procedure (if that’s what actually needs to be done).

Setting up an activation procedure is a bit tricky as you have to have the queue to create the procedure, and you have to have the procedure to set it as an activation procedure.  So what I like to do is create the queue, then the procedure, then alter the queue to setup the activation.  This way I can send messages to the queue right away without worrying about getting errors because the procedure doesn’t exist.

Unlike tables, you do not get to define the structure of the queue.  All data is stored within the message_body field, so if you need to send more than one value it’s recommend that you use an XML document to send the data.  The syntax to create the queue is very simply.

CREATE QUEUE [QueueName]

Because the queue does hold the messages you can define what file group you would like the data within the queue to be stored in.  If you have a business need to keep the messages around after processing you can specify the RETENTION keyword setting it to ON.  By default queues are enabled when they are created.  If you do not want to allow messages to be delivered to the queue specify the STATUS keyword setting it to OFF.

Denny


Contact the Author | Contact DCAC

Video

Globally Recognized Expertise

As Microsoft MVP’s and Partners as well as VMware experts, we are summoned by companies all over the world to fine-tune and problem-solve the most difficult architecture, infrastructure and network challenges.

And sometimes we’re asked to share what we did, at events like Microsoft’s PASS Summit 2015.

Awards & Certifications

Microsoft Partner    Microsoft MVP    Microsoft Certified Master    VMWare Partner    VMWare vExpert
   Best Full-Service Cloud Technology Consulting Company    Insights Sccess Award    Technology Headlines Award    Golden Bridge Gold Award    CIO Review Top 20 Azure Solutions Providers
Share via
Copy link