More on SQL Server Service Broker

來源:互聯網
上載者:User

In earlier posts I already blogged about creating some simple queuing solutions with SQL Server Service Broker. Last week I spend some time actually implementing my research in a customer project and of course ran into two 'interesting' issues.

  1. It is possible for the Service Broker to somehow die on you, whilst appearing to be up and running and with RETENTION=ON sent message appear to be in the queue.

    When using the SQL Profiler it becomes clear that messages don't get processed because the Service Broker is not enabled.

    You can use the following statement to enable Service Broker:

    alter database PFA_DATA set ENABLE_BROKER

    I had to do it on two machines and on of them gave me the following error:

    Msg 9772, Level 16, State 1, Line 2
    The Service Broker in database "PFA_DATA" cannot be enabled because there is already an enabled Service Broker with the same ID.
    Msg 5069, Level 16, State 1, Line 2
    ALTER DATABASE statement failed.

    So instead I used:

    alter database PFA_DATA set NEW_BROKER

    After this the Service Broker was up and running and message started getting delivered.

    If the query takes extremely long to complete restart SQL Server and try again.

    One potential cause for this is when you restore a database.

  2. In my earlier post I just blatantly used WITH CLEANUP to avoid getting EndDialog messages.
    The documentation however states:

    WITH CLEANUP
    Remove all messages and catalog view entries for this side of the conversation without notifying the other side of the conversation. Microsoft SQL Server drops the conversation endpoint, all messages for the conversation in the transmission queue, and all messages for the conversation in the service queue. Use this option to remove conversations which cannot complete normally. For example, if the remote service has been permanently removed, you use WITH CLEANUP to remove conversations to that service.

    So use this sparingly.

    I've discovered a much cleaner way to handle it.
    When sending a message you can use "END CONVERSATION @dialog" to specify that as far as the sender is concerned the dialog is over. In other words: a fire and forget message.
    When the receiving side of the conversation receives the messages and performs its "END CONVERSATION" statement, Service Broker will detect that no acknowledgement (EndDialog) needs to be send.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.