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;