SQL Server clears the queue statement in the service broker

Source: Internet
Author: User

Copy codeThe Code is as follows:
USE TestDB
Declare @ conversation uniqueidentifier
While exists (select 1 from sys. transmission_queue)
Begin
Set @ conversation = (select top 1 conversation_handle from sys. transmission_queue)
End conversation @ conversation with cleanup
End

If the messages received by the client are not processed, they will also be accumulated in the client queue. In fact, this is equivalent to many unread emails. We can use the following script to read the queue. After reading the message, the queue is automatically cleared:
Copy codeThe Code is as follows:
USE TestDB
DECLARE @ RecvReplyMsg NVARCHAR (100 );
DECLARE @ RecvReplyDlgHandle UNIQUEIDENTIFIER;
Begin transaction;
WHILE (1 = 1)
BEGIN
WAITFOR
(Receive top (1)
@ RecvReplyDlgHandle = conversation_handle,
@ RecvReplyMsg = message_body
FROM dbo. Test_TargetQueue
), TIMEOUT 1000;
End conversation @ RecvReplyDlgHandle;
SELECT @ RecvReplyMsg AS ReceivedReplyMsg;
END
Commit transaction;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.