请教 SQL2005 Service Broker 异步消息队列 20wangjia184]

发布时间:2016-12-6 22:23:24 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"请教 SQL2005 Service Broker 异步消息队列 20wangjia184]",主要涉及到请教 SQL2005 Service Broker 异步消息队列 20wangjia184]方面的内容,对于请教 SQL2005 Service Broker 异步消息队列 20wangjia184]感兴趣的同学可以参考一下。

大家帮帮忙 用简单的代码说说

http://www.microsoft.com/china/msdn/library/data/sqlserver/sqlsvcbroker.mspx?mfr=true

BOOKS ONLINE

How to Create Contracts 1Create message types CREATE MESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim] VALIDATION = WELL_FORMED_XML CREATE MESSAGE TYPE [//Adventure-Works.com/Expenses/ClaimResponse] VALIDATION = VALID_XML WITH SCHEMA COLLECTION awschemas CREATE MESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim] VALIDATION = WELL_FORMED_XML CREATE MESSAGE TYPE [//Adventure-Works.com/Expenses/ClaimResponse] 2 Create contract CREATE CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense] ( [//Adventure-Works.com/Expenses/ExpenseClaim] SENT BY INITIATOR, [// Adventure-Works.com/Expenses/ClaimResponse] SENT BY TARGET ) How to Create Queues 1 Create queue name Create 2 Choose whether queue is available 3 Specify any activation parameters CREATE QUEUE ExpenseQueue CREATE QUEUE ExpenseQueueWithActivation WITH STATUS = OFF, ACTIVATION ( PROCEDURE_NAME = ProcessExpense, MAX_QUEUE_READERS = 5, EXECUTE AS SELF) CREATE How to Create Services 1 Create service name Create 2 Choose storage queue Choose 3 List contracts for which the service is a target List 4 Choose whether to retain messages for conversation lifetime Choose CREATE SERVICE [//Adventure-Works.com/SubmitExpense] ON QUEUE ExpenseQueue ( [//Adventure-Works.com/Expenses/ProcessExpense] ) CREATE SERVICE [//Adventure-Works.com/SubmitExpense] ON QUEUE ExpenseQueue ( [//Adventure-Works.com/Expenses/ProcessExpense] ) How to Send a Message 1 Declare a dialog handle variable 2 Begin a dialog conversation 3 Send the message  DECLARE @dialog_handle uniqueidentifier BEGIN DIALOG CONVERSATION @dialog_handle FROM SERVICE [//Adventure-Works.com/SubmitExpense] TO SERVICE '//Adventure-Works.com/ProcessExpense' ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense] ;SEND ON CONVERSATION @dialog_handle MESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim] (@msgString) DECLARE @dialog_handle uniqueidentifier BEGIN DIALOG CONVERSATION @dialog_handle FROM SERVICE [//Adventure-Works.com/SubmitExpense] TO SERVICE '//Adventure-Works.com/ProcessExpense' ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense] ;SEND ON CONVERSATION @dialog_handle MESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim] (@msgString) How to Receive a Message 1 Declare variables for storing message details 2 Call RECEIVE statement 3 Check the message type, and process accordingly  4 If finished conversation, call END CONVERSATION  DECLARE @conversation UNIQUEIDENTIFIER DECLARE @msg NVARCHAR(conversation_name, @msg = message_body FROM ExpenseQueue MAX), @msgType NVARCHAR(256) ;RECEIVE TOP(1) @conversation_name, @msg = message_body FROM ExpenseQueue handle, @msgType = message_type_IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim') -- process @msg … conversation = handle, @msgType = message_type_IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim') -- process @msg … DECLARE @conversation UNIQUEIDENTIFIER DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256) ;RECEIVE TOP(1) @conversation = END CONVERSATION @conversation END CONVERSATION @conversation

汗!!

强,学习。

上一篇:SQL 2005 DCOM错误 20CSDN]
下一篇:谁能帮我解释一下,SQL2005里的架构?拜托啦~ 100kywlw]

相关文章

相关评论