SQLServerXMLSupport•Chapter11 517 Self Test Quick Answer Key 1. D 2. C 3. A 4. B 5. C 6. C 7. C 8. D 9. D 10. B 11. C 12. B 13. A 14. A 15. D 16. D 17. A 18. B 19. D 20. D This page intentionally left blank 519 Exam objectives review: ˛ Summary of Exam Objectives ˛ Exam Objectives Fast Track ˛ Exam Objectives Frequently Asked Questions ˛ Self Test ˛ Self Test Quick Answer Key Exam objectives in this chapter: The Queuing Concept Explained Service Broker Defined Message Types Contracts Queues Services Routes Sending a Message Service Broker Chapter 12 MCTS SQL Server 2008 Exam 432 520 Chapter12•ServiceBroker Introduction This chapter will introduce the DBA to SERVICE BROKER. It will explain what SERVICE BROKER is, how to set it up, and how to test to be sure it’s functioning. It will also educate the DBA on some of the uses for SERVICE BROKER. SERVICE BROKER is commonly used for asynchronous tasks. The concept of messages and queues is explained in this chapter, along with contracts and message types. The Queuing Concept Explained The concept of message queuing has been around for many years. Microsoft has included message queuing as an available option within the operating system since Windows NT 4.0. Starting with SQL Server 2005, the SQL SERVICE BROKER (SSB) has been included within the database platform. SQL SERVICE BROKER, like all message queuing technologies, allows for asynchronous messages to be sent from one server to another with the receiving server processing that message and carrying out some predefined task. A simple analogy is that one process within SQL Server is going to send an e-mail to another process within SQL Server. The second process will read the message and do something based on the contents of that message. The beauty of SQL SERVICE BROKER is that the something that it does is totally up to the developer of the stored procedure that is going to be run. The beauty of message queuing in general is that message delivery is guaranteed in the order sent, as is the fact that a message can be received only once. What this means is that no matter how many people are sending messages to the receiving system the messages will always be processed in the correct order that they were sent, and the receiving system can receive them once and only once. This will prevent the system from reprocessing the same message twice and causing errors because of processing the same message twice. The only way a message can be processed twice would be if the sending system sent the same message text as two separate messages. Whereas other messaging systems like Microsoft Message Queue (MSMQ) can be accessed directly by Windows applications or applications on other operating systems, SQL SERVICE BROKER does not currently support this. In order to send or receive a message you have to log in to the SQL Server database. Neither Microsoft nor any third party as of this writing has written a way to send or receive messages without connecting to the SQL Server database. Because of this, SQL SERVICE BROKER may not always be the correct solution for your messaging ServiceBroker•Chapter12 521 environment. If the messages are not going to be sent or received by T/SQL then SQL SERVICE BROKER may not be your best option. Service Broker Defined There are two main concepts within SQL SERVICE BROKER: sending and receiving messages. Any process can send a message, provided it has the required rights to do so. Messages can be received on demand—for example, through a SQL Server job performing a RECEIVE command on the queue or by a Windows application logging into the database and performing a RECEIVE command on the queue. Messages can also be received and processed automatically by using what is called an activated stored procedure. The activated stored procedure is a normal stored procedure that is started automatically by the receiving queue when a message is received. The procedure would then RECEIVE the message and process the contents of the message as needed (we will examine this more closely later in the chapter). Any database within the SQL Server instance can use the SQL SERVICE BROKER including the system databases. It is recommended, however, that you not make any changes to the SQL SERVICE BROKER within the system databases because SQL Server uses the SERVICE BROKER for its own tasks. In fact, even if you have never used SQL SERVICE BROKER before, if you use SQL Mail to send e-mails from the SQL Server you are using SQL SERVICE BROKER, because SQL Mail uses the SERVICE BROKER to queue the messages for sending. The SQL SERVICE BROKER is a collection of objects within the database that when configured can be used to send messages from one process to another. These messages can be sent within the same database, to another database within the same instance of SQL Server, to another database in another SQL Server instance on the same server, or to another SQL Server instance on another server either within your company’s network or to another company’s network. There are a few Dynamic Management Views (DMVs) that are used to gauge the health and performance of the SERVICE BROKER system. Of these the most important when troubleshooting SQL SERVER BROKER issues are the sys.conver- sation_endpoints and the sys.transmission_queue. The sys.conversation_endpoints is used most often to troubleshoot issues when sending messages from one queue to another within the same database; the sys.transmission_queue is used most often to troubleshoot issues when sending messages from one database to another. With regard to the SQL SERVICE BROKER it is important to remember that when we speak of sending messages from one database we are talking about sending messages within the instance of SQL Server or across servers. . another. These messages can be sent within the same database, to another database within the same instance of SQL Server, to another database in another SQL Server instance on the same server, . within the SQL Server instance can use the SQL SERVICE BROKER including the system databases. It is recommended, however, that you not make any changes to the SQL SERVICE BROKER within the system. SQL Server uses the SERVICE BROKER for its own tasks. In fact, even if you have never used SQL SERVICE BROKER before, if you use SQL Mail to send e-mails from the SQL Server you are using SQL