http://www.sqlpass.org/24hours/Fall2010/ September 15-16, 2010
` http://www.sqlpass.org/summit/na2010/ November 8-11, 2010 Seattle, Washington
Purpose and Objectives Provide an introduction to Service Broker What Service Broker can do Define Service Broker Terms Sample code
What Service Broker Can Do Native support for messaging and queuing applications –Conversations –Message ordering and coordination Build distributed applications –Workload balancing –N-tier applications Transactional asynchronous processing
What Service Broker Can Do Take advantage of Service Oriented Architecture (SOA) Workflow (WF) BizTalk Microsoft Message Queuing (MSMQ)
Service Broker Terms – Message Type A MESSAGE TYPE defines the name of a message and the validation that Service Broker performs on this message. Both sides of a conversation must define the same message types. –Validation NONEWhatever you want in the message body (stored as varbinary(max)) EMPTYThe message body must be null. WELL_FORMED_XMLThe body must contain well formed xml.
Service Broker Terms - Initiator An Initiator is the service that starts a conversation. (BEGIN DIALOG) A service can be both an Initiator and a Target but on different conversations.
Service Broker Terms - Target A Target is a service that accepts a conversation that was started by another service. A service can be both an Initiator and a Target but on different conversations.
Service Broker Terms - Contract A CONTRACT defines the message types used in a broker conversation and which party in the conversation can send them.
Service Broker Terms - Queue A QUEUE is where Service Broker stores messages. A QUEUE is a ‘hidden table’ and is a schema-owned object. Like any other table it can be placed on a file group. A QUEUE has a status that is –ONmessages can be added and removed –OFFmessages cannot be added or removed.
Service Broker Terms - Queue A QUEUE has an Activation Status that may identify the stored procedure to process messages in the queue and how many instances of the procedure may run concurrently. When a QUEUE is unavailable messages are held in a transmission queue for the database, sys.transmission_queue.
Service Broker Terms - Queue POISON_MESSAGE_HANDLING –ONThe default. The QUEUE will be disabled, STATUS = OFF, when there are five consecutive transaction rollbacks. –OFFThe QUEUE will not be disabled by service broker because of transaction rollbacks.
Service Broker Terms - Queue A QUEUE can be queried with SELECT. –To prevent locking the queue SELECT * FROM schema.queue WITH(NOLOCK); It cannot be modified with INSERT, UPDATE or DELETE statements.
Service Broker Terms - Service A SERVICE is a name for a specific task or set of tasks and is used to route messages to the correct QUEUE and enforce CONTRACT constraints. A SERVICE identifies a QUEUE and a list of CONTRACTs that the service uses.
Service Broker Terms - Route A ROUTE identifies which network address a Service Broker service is located on. Whenever you want your messages to leave the database they originate in, you need to provide a ROUTE. ROUTE is not covered in this presentation.
Environment Automatically installed beginning with SQL2005 Service Broker External Activator is available with SQL Server 2008 Feature Pack –Lets you move logic to receive and process messages from the server engine to an executable. http://www.microsoft.com/downloads/details.aspx?FamilyId=228DE03F-3B5A-428A-923F- 58A033D316E1&displaylang=en http://www.microsoft.com/downloads/details.aspx?FamilyId=228DE03F-3B5A-428A-923F- 58A033D316E1&displaylang=en The model database has Broker Enabled = false –CREATE DATABASE creates a database with Broker Enabled = true despite the model setting.
Message Performance The techniques you use for tuning other applications apply to tuning Service Broker applications Source Pro SQL Server 2008 Service Broker by Klause Aschenbrenner APress
Demo SQL Server event notifications –Sample code to process SQL Server event notifications The code will provide a history record for all DDL changes made on an SQL Server. (Quite a bit less than source code management) –Demonstrate how to RECEIVE messages Set processing Row by agonizing row Sending and Receiving messages –A explanation of the basic code to SEND and RECEIVE a message. An order application that sends a message to three different services which process them asynchronously and send back a reply. The Service Broker Application Template.
Additional Information Pro SQL Server 2008 Service Broker Klaus Aschenbrenner http://www.apress.com/book/view/1590599993 http://www.apress.com/book/view/1590599993 A brief guide to SQL Server Service Broker http://blogs.msdn.com/b/kangmo/archive/2008/12/17/a-brief-guide-on-sql-server-service- broker.aspx http://blogs.msdn.com/b/kangmo/archive/2008/12/17/a-brief-guide-on-sql-server-service- broker.aspx SQL Server: Service Broker Team Blog http://blogs.msdn.com/b/sql_service_broker/rss.aspx http://blogs.msdn.com/b/sql_service_broker/rss.aspx A simple secure dialog with transport certificates http://blogs.msdn.com/b/sql_service_broker/archive/2008/06/10/a-simple-secure-dialog-with- certificates.aspx http://blogs.msdn.com/b/sql_service_broker/archive/2008/06/10/a-simple-secure-dialog-with- certificates.aspx Announcing Service Broker External Activator http://social.msdn.microsoft.com/Forums/en-US/sqlservicebroker/thread/36a58004-dbef-46ad- 85a2-93563f3f8f0ehttp://social.msdn.microsoft.com/Forums/en-US/sqlservicebroker/thread/36a58004-dbef-46ad- 85a2-93563f3f8f0e Sample activated application http://blogs.msdn.com/b/sql_service_broker/archive/2010/03/10/sample-activated-application.aspxhttp://blogs.msdn.com/b/sql_service_broker/archive/2010/03/10/sample-activated-application.aspx Get Started With Using External Activator http://blogs.msdn.com/b/sql_service_broker/archive/2009/05/18/get-started-with-using-external- activator.aspx http://blogs.msdn.com/b/sql_service_broker/archive/2009/05/18/get-started-with-using-external- activator.aspx Service Broker: Performance and Scalability Techniques http://technet.microsoft.com/en-us/library/dd576261(SQL.100).aspxhttp://technet.microsoft.com/en-us/library/dd576261(SQL.100).aspx Service Broker Tutorials http://msdn.microsoft.com/en-us/library/bb839489.aspxhttp://msdn.microsoft.com/en-us/library/bb839489.aspx Building a Distributed Service Broker Application http://www.sqlservercentral.com/articles/Service+Broker/2797/http://www.sqlservercentral.com/articles/Service+Broker/2797/
Additional Information The Service Broker Alphabet Part 1 http://www.sqlservercentral.com/articles/Service+Broker/2807/http://www.sqlservercentral.com/articles/Service+Broker/2807/ The Service Broker Alphabet Part 2 http://www.sqlservercentral.com/articles/Service+Broker/2808/http://www.sqlservercentral.com/articles/Service+Broker/2808/ Async Lifestyle: Manage Your Tasks With Service Broker http://technet.microsoft.com/en-us/magazine/2005.05.servicebroker.aspxhttp://technet.microsoft.com/en-us/magazine/2005.05.servicebroker.aspx SQL Server Service Broker - An Introduction http://www.databasejournal.com/features/mssql/article.php/3880191/SQL-Server-Service-Broker--- An-Introduction.htmhttp://www.databasejournal.com/features/mssql/article.php/3880191/SQL-Server-Service-Broker--- An-Introduction.htm Writing an SSBS App When the Initiator and Target are on the Same Database http://www.databasejournal.com/features/mssql/article.php/3896201/Writing-an-SSBS-App-When- the-Initiator-and-Target-are-on-the-Same-Database.htmhttp://www.databasejournal.com/features/mssql/article.php/3896201/Writing-an-SSBS-App-When- the-Initiator-and-Target-are-on-the-Same-Database.htm Service Broker Troubleshooting http://www.mssqltips.com/tip.asp?tip=1197 http://www.mssqltips.com/tip.asp?tip=1197 Service Broker Wait Types http://blogs.msdn.com/b/sql_service_broker/archive/2008/12/01/service-broker-wait-types.aspx http://blogs.msdn.com/b/sql_service_broker/archive/2008/12/01/service-broker-wait-types.aspx