Presentation on theme: "SQL Server Service Broker The South East Michigan SQL Server Users Group Tom Groszko"— Presentation transcript:
SQL Server Service Broker The South East Michigan SQL Server Users Group Tom Groszko
September 15-16, 2010
` 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. 58A033D316E1&displaylang=en 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 A brief guide to SQL Server Service Broker broker.aspx broker.aspx SQL Server: Service Broker Team Blog A simple secure dialog with transport certificates certificates.aspx certificates.aspx Announcing Service Broker External Activator 85a f3f8f0ehttp://social.msdn.microsoft.com/Forums/en-US/sqlservicebroker/thread/36a58004-dbef-46ad- 85a f3f8f0e Sample activated application Get Started With Using External Activator activator.aspx activator.aspx Service Broker: Performance and Scalability Techniques Service Broker Tutorials Building a Distributed Service Broker Application
Additional Information The Service Broker Alphabet Part 1 The Service Broker Alphabet Part 2 Async Lifestyle: Manage Your Tasks With Service Broker SQL Server Service Broker - An Introduction An-Introduction.htmhttp://www.databasejournal.com/features/mssql/article.php/ /SQL-Server-Service-Broker--- An-Introduction.htm Writing an SSBS App When the Initiator and Target are on the Same Database the-Initiator-and-Target-are-on-the-Same-Database.htmhttp://www.databasejournal.com/features/mssql/article.php/ /Writing-an-SSBS-App-When- the-Initiator-and-Target-are-on-the-Same-Database.htm Service Broker Troubleshooting Service Broker Wait Types