Home > Database > Mysql Tutorial > sqlserver清空service broker中的队列的语句分享

sqlserver清空service broker中的队列的语句分享

WBOY
Release: 2016-06-07 18:02:17
Original
1074 people have browsed it

在我们开发service broker应用时候,可能用于测试或者客户端没有配置正确等导致服务端队列存在很多垃圾队列,不便于我们排查错误,我们可以使用SQL脚本来清空服务端这些垃圾数据

代码如下:
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

那么客户端接受到的消息如果没有处理,也会积攒在客户端队列中,其实就相当于许多未读邮件,我们可以使用以下脚本读取队列 ,读取后队列自动清空:
代码如下:
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 labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template