<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title> Mat Stephen's SQL Server WebLog : Service Broker</title><link>http://blogs.technet.com/mat_stephen/archive/tags/Service+Broker/default.aspx</link><description>Tags: Service Broker</description><dc:language>en-GB</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Getting to know SQL 2005 Service Broker</title><link>http://blogs.technet.com/mat_stephen/archive/2005/09/12/ServiceBroker.aspx</link><pubDate>Tue, 13 Sep 2005 00:27:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:410667</guid><dc:creator>Mat_Stephen</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/mat_stephen/comments/410667.aspx</comments><wfw:commentRss>http://blogs.technet.com/mat_stephen/commentrss.aspx?PostID=410667</wfw:commentRss><description>&lt;P&gt;Looks likes I've got to do&amp;nbsp;a presentation on Service Broker for the SQL 2005 launch - so I've been doing some home work on the subject.&lt;/P&gt;
&lt;P&gt;The best primer I've found is &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/sqlsvcbroker.asp?frame=true"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/sqlsvcbroker.asp?frame=true&lt;/A&gt;&amp;nbsp;this is refernenced in the webcast &lt;A href="http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032263311&amp;amp;EventCategory=5&amp;amp;culture=en-us&amp;amp;CountryCode=US"&gt;http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032263311&amp;amp;EventCategory=5&amp;amp;culture=en-us&amp;amp;CountryCode=US&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you've got your head round the basics you'll want to create your ow broker service and queues.&amp;nbsp; Best I've found is "Setting Up a Service Broker Service and Queue" from SQL Server 2005 Books on line at ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/smo9/html/f6f1c8b5-393b-48f2-a2b0-184fef683b5c.htm.&amp;nbsp; Problem with this is there's a bug in the code.&amp;nbsp; I can't remember the delta between what's printed and what I have working, but my suggestion is to use the code below to create the TargetStoredProcedure and then comment out the sp.Create(); line in the sample code with //.&lt;/P&gt;
&lt;P&gt;Hope you enjoy this new technology - if I discover some new usefulties (a new word I've just invented) in this area, I'll post them in my new 'Service Broker' category&lt;/P&gt;
&lt;P&gt;USE [AdventureWorks]&lt;BR&gt;GO&lt;BR&gt;/****** Object:&amp;nbsp; StoredProcedure [dbo].[TargetStoredProcedure]&amp;nbsp;&amp;nbsp;&amp;nbsp; Script Date: 09/12/2005 23:17:28 ******/&lt;BR&gt;SET ANSI_NULLS ON&lt;BR&gt;GO&lt;BR&gt;SET QUOTED_IDENTIFIER ON&lt;BR&gt;GO&lt;BR&gt;create procedure dbo.TargetStoredProcedure as&lt;BR&gt;DECLARE @message_body varbinary(MAX); &lt;BR&gt;DECLARE @message_type_name nvarchar(128); &lt;BR&gt;DECLARE @conversation_handle uniqueidentifier; &lt;BR&gt;DECLARE @message_iduniqueidentifier uniqueidentifier; &lt;BR&gt;DECLARE @message nvarchar(max); &lt;BR&gt;DECLARE @MessageType nvarchar(max); &lt;BR&gt;Declare @message_id nvarchar(max); &lt;/P&gt;
&lt;P&gt;WHILE (1 = 1) &lt;BR&gt;BEGIN &lt;BR&gt;BEGIN TRY &lt;BR&gt;BEGIN TRANSACTION; &lt;BR&gt;WAITFOR ( &lt;/P&gt;
&lt;P&gt;RECEIVE top(1) &lt;BR&gt;@message_type_name = message_type_name, &lt;BR&gt;@message = message_body, &lt;BR&gt;@conversation_handle = conversation_handle, &lt;BR&gt;@message_id = message_id &lt;/P&gt;
&lt;P&gt;FROM TargetQueue &lt;BR&gt;), TIMEOUT 500 &lt;/P&gt;
&lt;P&gt;IF (@@ROWCOUNT = 0) &lt;BR&gt;BEGIN &lt;BR&gt;ROLLBACK TRANSACTION &lt;BR&gt;BREAK &lt;BR&gt;END; &lt;BR&gt;select @message = N'&amp;lt;Hello&amp;gt;Pong&amp;lt;/Hello&amp;gt;'; &lt;BR&gt;set @MessageType = '//microsoft.com/ssbdemo/PongMessageType'; &lt;BR&gt;SEND ON CONVERSATION @conversation_handle &lt;BR&gt;MESSAGE TYPE @MessageType &lt;BR&gt;(@message); &lt;BR&gt;END CONVERSATION @conversation_handle &lt;BR&gt;COMMIT TRANSACTION &lt;BR&gt;END TRY &lt;BR&gt;BEGIN CATCH &lt;BR&gt;print @@error; &lt;BR&gt;ROLLBACK &lt;BR&gt;CONTINUE &lt;BR&gt;END CATCH &lt;BR&gt;END; &lt;BR&gt;GO&lt;BR&gt;SET ANSI_NULLS OFF&lt;BR&gt;GO&lt;BR&gt;SET QUOTED_IDENTIFIER OFF&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=410667" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/mat_stephen/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.technet.com/mat_stephen/archive/tags/SQL+Server+2005/default.aspx">SQL Server 2005</category><category domain="http://blogs.technet.com/mat_stephen/archive/tags/Webcasts/default.aspx">Webcasts</category><category domain="http://blogs.technet.com/mat_stephen/archive/tags/T-SQL/default.aspx">T-SQL</category><category domain="http://blogs.technet.com/mat_stephen/archive/tags/Architects+Corner/default.aspx">Architects Corner</category><category domain="http://blogs.technet.com/mat_stephen/archive/tags/Service+Broker/default.aspx">Service Broker</category></item></channel></rss>