Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

654


Part V: Enterprise Data Management


BREAK ;
END ;

-- Process all messages in the conversation group. Notice
-- that all processing occurs in the same transaction.

WHILE 1 = 1
BEGIN

-- Receive the next message for the conversation group.
-- Notice that the receive statement includes a WHERE
-- clause to ensure that the messages received belong to
-- the same conversation group.

RECEIVE
TOP(1)
@conversation_handle = conversation_handle,
@message_type_name = message_type_name,
@message_body =
CASE
WHEN validation = 'X' THEN CAST(message_body AS XML)
ELSE CAST(N'<none/>' AS XML)
END
FROM [dbo].[TargetQueue]
WHERE conversation_group_id = @conversation_group_id ;

-- If there are no more messages, or an error occurred,
-- stop processing this conversation group.

IF @@ROWCOUNT = 0 OR @@ERROR <> 0 BREAK;

-- Show the information received.

SELECT 'Conversation Group Id' = @conversation_group_id,
'Conversation Handle' = @conversation_handle,
'Message Type Name' = @message_type_name,
'Message Body' = @message_body ;

-- If the message_type_name indicates that the message is
an error or an end dialog message, end the conversation.

IF @message_type_name =
'http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog'
OR @message_type_name =
'http://schemas.microsoft.com/SQL/ServiceBroker/Error'
BEGIN
END CONVERSATION @conversation_handle ;

c25.indd 654c25.indd 654 7/31/2012 9:21:38 AM7/31/2012 9:21:38 AM


http://www.it-ebooks.info
Free download pdf