IN THIS CHAPTER
Defining a work queue
Service Broker is a powerful yet simple work queue system that can be used to add asynchronous messaging and work queues to a database abstraction layer to provide high scalability, and it is essential in any SOA data store architecture.
If you've ever built a table to hold work to be done, such as orders to be processed by a Materials Requirement Planning system, then you've built a work queue. In one application Service Broker is just that—a high-performance, wide-payload work queue integrated into SQL Server with DDL and monitoring capabilities.
Service Broker can also be used to pass messages with guaranteed secure delivery between work queues, which opens up a world of possibilities.
Because Service Broker is essentially just a SQL Server table, it includes all the cool transactional and back-up capabilities inherent to SQL Server. This is what sets Service Broker apart from other queuing technologies, such as Microsoft Message Queuing (MSMQ).
The queue contains a single, wide column for the message body, which is OK because the message will typically contain a single XML file or fragment or SOAP message as the payload.
Service Broker is not enabled by default so the first specific step to working with Service Broker is to turn it on using the
ALTER DATABASE command:
ALTER DATABASE AdventureWorks SET ENABLE_BROKER;