如何删除服务代理队列中的消息

时间:2012-05-31 07:46:13

标签: sql-server queue service-broker

我想清除SQL Server Management Studio中的队列,但我不想只删除整个队列中的队列内容(消息)。

谢谢, 番泻叶

5 个答案:

答案 0 :(得分:44)

为了清楚起见,将前两个答案(Ben和Jānis)结合起来。这对我有用:

declare @c uniqueidentifier
while(1=1)
begin
    select top 1 @c = conversation_handle from dbo.queuename
    if (@@ROWCOUNT = 0)
    break
    end conversation @c with cleanup
end

答案 1 :(得分:13)

这样的事情应该有效:

while(1=1)
begin
    waitfor (
        receive top(1)
        conversation_group_id
        from dbo.yourQueue
    ), timeout 1000;

    if (@@rowcount = 0)
        break;
end

答案 2 :(得分:10)

我会使用end conversation(也将删除所有队列中的所有相关消息)使用语句:

End Converstation @c With CleanUp

如果你刚收到消息,那么你就会打开对话。 结束对话使用CleanUp仅适用于特定情况。

答案 3 :(得分:1)

如果您使用的是SQL Server(从2008年开始),您可以使用RECEIVE

WHILE (0=0)
BEGIN
RECEIVE * FROM Dbo.YourQueue;
IF (@@ROWCOUNT = 0)BREAK;
END

答案 4 :(得分:-2)

while(1=1)
begin
    waitfor (
        receive top(1)
        conversation_group_id
        from kartokumaqueue2), timeout 1000;

        if(@@ROWCOUNT = 0) break;
end
相关问题