{"id":729,"date":"2008-01-21T11:31:00","date_gmt":"2008-01-21T11:31:00","guid":{"rendered":"\/blogs\/bobb\/post\/Service-Broker-in-SQL-Server-2008-Priority-By-Contract.aspx"},"modified":"2013-01-07T09:00:24","modified_gmt":"2013-01-07T17:00:24","slug":"service-broker-in-sql-server-2008-priority-by-contract","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/","title":{"rendered":"Service Broker in SQL Server 2008 &#8211; Priority By Contract"},"content":{"rendered":"<p>\nConversation priority is a new feature with SQL Server 2008. In a <a href=\"http:\/\/3.209.169.194\/blogs\/bobb\/service-broker-priorities-in-sql-server-2008-ctp5-an-overview\/\" class=\"broken_link\">previous blog post<\/a>, I talked about how to simply set one up. But you&#39;d usually not want to set up a priority for all messages. So, lets set up a simple service and then define a &quot;Premier Customer&quot; priority. Before trying this you need to make sure the database is set to honor broker priority.\n<\/p>\n<p>\nALTER DATABASE pubs SET HONOR_BROKER_PRIORITY ON;\n<\/p>\n<p>\nSuppose I had a simple (one database) service pair. A service called &quot;sender&quot; (note lower case) using senderq is the initiator and a service called &quot;receiver&quot; using receiverq is the target. They use the [default] contract. So we can set up a &quot;Premier Customer&quot; by contract.\n<\/p>\n<p>\nCREATE CONTRACT premier ([DEFAULT] SENT BY ANY);<br \/>\nGO\n<\/p>\n<p>\nNow, let&#39;s ensure that the target can also use the premier contract in addition to the DEFAULT contract.\n<\/p>\n<p>\nALTER SERVICE receiver ON QUEUE receiveq (ADD CONTRACT premier);\n<\/p>\n<p>\nWe need to set up the priority.\n<\/p>\n<p>\nCREATE BROKER PRIORITY PremierCustomer<br \/>\n&nbsp;&nbsp;&nbsp; FOR CONVERSATION<br \/>\n&nbsp;&nbsp;&nbsp; SET (CONTRACT_NAME = premier,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOCAL_SERVICE_NAME = sender,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; REMOTE_SERVICE_NAME = &#39;receiver&#39;,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRIORITY_LEVEL = 7);<br \/>\nGO\n<\/p>\n<p>\nThe interesting thing is, this priority ONLY covers messages sent and received (and get conversation group) by the sender\/senderq, IT DOESN&#39;T cover the receives in the receiver\/receiveq queue. So we&#39;ll set up a mirror image priority, and make the priority level still higher than the default (5) but gratuitously different than the other priority\n<\/p>\n<p>\nCREATE BROKER PRIORITY PremierCustomer2<br \/>\n&nbsp;&nbsp;&nbsp; FOR CONVERSATION<br \/>\n&nbsp;&nbsp;&nbsp; SET (CONTRACT_NAME = premier,<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOCAL_SERVICE_NAME = receiver,&nbsp;&nbsp; &#8212; local service is receiver<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; REMOTE_SERVICE_NAME = &#39;sender&#39;, &#8212; remote service is sender<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRIORITY_LEVEL = 6);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212; note level 6, not 7<br \/>\nGO\n<\/p>\n<p>\nNow, begin a conversation using sender and receiver and the premier contract&nbsp;and send a message. Note that when you issue &quot;SELECT * FROM sys.conversation_endpoints;&quot; the sender (initiator&#39;s) endpoint is priority 7, the receiver&#39;s endpoint is priority 6. And, looking at the message in the receiveq its set to priority 6.\n<\/p>\n<p>\nIf you&#39;d send a return message from the receiver (target) back to the sender (initiator), the return message in the senderq would be priority 7.\n<\/p>\n<p>\nSo when setting up priorities, if you want all messages on both sides to be affected, don&#39;t forget to set up a priority for EACH side. Here&#39;s the entire demo.\n<\/p>\n<p><a href=\"http:\/\/3.209.169.194\/blogs\/bobb\/content\/binary\/brokerprioritybycontractdemo.zip\" class=\"broken_link\">BrokerPriorityByContractDemo.zip (1.57 KB)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Conversation priority is a new feature with SQL Server 2008. In a previous blog post, I talked about how to simply set one up. But you&#39;d usually not want to set up a priority for all messages. So, lets set up a simple service and then define a &quot;Premier Customer&quot; priority. Before trying this you [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,29],"tags":[],"class_list":["post-729","post","type-post","status-publish","format-standard","hentry","category-service-broker","category-sql-server-2008"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Service Broker in SQL Server 2008 - Priority By Contract - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Service Broker in SQL Server 2008 - Priority By Contract - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"Conversation priority is a new feature with SQL Server 2008. In a previous blog post, I talked about how to simply set one up. But you&#039;d usually not want to set up a priority for all messages. So, lets set up a simple service and then define a &quot;Premier Customer&quot; priority. Before trying this you [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2008-01-21T11:31:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-01-07T17:00:24+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/\",\"name\":\"Service Broker in SQL Server 2008 - Priority By Contract - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2008-01-21T11:31:00+00:00\",\"dateModified\":\"2013-01-07T17:00:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Service Broker\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/service-broker\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Service Broker in SQL Server 2008 &#8211; Priority By Contract\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Service Broker in SQL Server 2008 - Priority By Contract - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/","og_locale":"en_US","og_type":"article","og_title":"Service Broker in SQL Server 2008 - Priority By Contract - Bob Beauchemin","og_description":"Conversation priority is a new feature with SQL Server 2008. In a previous blog post, I talked about how to simply set one up. But you&#39;d usually not want to set up a priority for all messages. So, lets set up a simple service and then define a &quot;Premier Customer&quot; priority. Before trying this you [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/","og_site_name":"Bob Beauchemin","article_published_time":"2008-01-21T11:31:00+00:00","article_modified_time":"2013-01-07T17:00:24+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/","name":"Service Broker in SQL Server 2008 - Priority By Contract - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2008-01-21T11:31:00+00:00","dateModified":"2013-01-07T17:00:24+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/service-broker-in-sql-server-2008-priority-by-contract\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"Service Broker","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/service-broker\/"},{"@type":"ListItem","position":3,"name":"Service Broker in SQL Server 2008 &#8211; Priority By Contract"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=729"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/729\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}