2016-09-12 16 views
2

私は、次の操作を実行することになり、ストアドプロシージャを書いています:Service Brokerのメッセージ

  1. はキックオフするバックグラウンド・プロセスをサービスブローカを使用するいくつかのタスク
  2. を行う
  3. トランザクションを開始
  4. Service Brokerからの応答メッセージ(ジョブステータス付き)を受け取ります。
  5. 応答メッセージに応じて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メッセージングを実装する正しい方法は何ですか?

  • 答えて

    4

    Service Broker経由でのメッ​​セージの送信はトランザクション処理です。つまり、begin tran; send;を実行すると、メッセージは実際には送信されません。commit

    関連する問題