2
私は、次の操作を実行することになり、ストアドプロシージャを書いています:Service Brokerのメッセージ
- はキックオフするバックグラウンド・プロセスをサービスブローカを使用するいくつかのタスク
- を行う
- トランザクションを開始
- Service Brokerからの応答メッセージ(ジョブステータス付き)を受け取ります。
- 応答メッセージに応じてCOMMITまたはROLLBACKトランザクション
問題は、サービスブローカ通信がTRANSACTION
内部の作業をしないことである:(ストアドプロシージャでPRINT
文がある
- メッセージキューが活性化が有効になっているが、関連したストアドプロシージャはが実行ありません
外)
RECEIVE
コマンド時間をファイルにエラーログに書き込まれません。ここに私の共同のエキスですde: -- Comment out the following line to make everything work
begin tran t1
DECLARE @Update_Msg XML([sb].[Service_Broker_xxx_Schemas]) = '
<Request xmlns="xxx">
<Table xmlns="xxx">
<Fields>
xxx
</Fields>
</Table>
<Requested_By>xxx</Requested_By>
</Request>'
DECLARE @conversation_handle UNIQUEIDENTIFIER
,@message_body varbinary(max)
,@message_type_name nvarchar(256)
,@timestamp datetime2
BEGIN DIALOG CONVERSATION @conversation_handle
FROM SERVICE [xxx_Initiating_Service]
TO SERVICE 'xxx_Target_Service'
ON CONTRACT xxx_Contract
WITH ENCRYPTION = OFF;
SEND ON CONVERSATION @conversation_handle
MESSAGE TYPE [xxx_Command](@Update_Msg);
select * from sys.transmission_queue with(nolock)
--PRINT @conversation_handle
WAITFOR (
-- just handle one message at a time
RECEIVE TOP(1) @conversation_handle = conversation_handle -- the identifier of the dialog this message was received on
,@message_type_name = message_type_name
,@message_body=message_body -- the message contents
,@timestamp = GETDATE()
FROM [sb].[xxx_Initiator_Queue]
WHERE conversation_handle = @conversation_handle
), TIMEOUT 1000 -- if the queue is empty for one second, give UPDATE and go away
IF @@ROWCOUNT > 0
BEGIN
SELECT @@ROWCOUNT, @message_type_name, CONVERT(XML, @message_body)
END CONVERSATION @conversation_handle;
END
ELSE
BEGIN
PRINT 'Did not receive any response from Service Broker.'
END
-- Comment out the following line to make everything work
commit tran t1
トランザクション内でService Brokerメッセージングを実装する正しい方法は何ですか?