¿Existe una forma rápida de eliminar una cola de Service Broker?

I have been running a load test that involves a Service Broker queue over night. Something went wrong and the queue ended up with 1.3 million messages in it. I just want to clear these out, no backup and no logging required. The trouble is that when I try to drop the queue it is taking half an hour and then the log file fills up and the whole thing rolls back. Is there a quick and dirty way of flushing everything out the queue?

preguntado el 08 de noviembre de 11 a las 10:11

2 Respuestas

You can clear all conversations at once with the following statement:

declare @conversationHandle uniqueidentifier 
select top 1 @conversationHandle = conversation_handle from sys.conversation_endpoints    
while @@rowcount = 1

begin    
     end conversation @conversationHandle with cleanup    
     select top 1 @conversationHandle = conversation_handle from sys.conversation_endpoints    
end

Respondido el 03 de enero de 12 a las 21:01

I'm sure this would have worked for me +1. There is a gotcha though: the situation where you have all the messages in a single conversation. In that case it may still run out of log space before the single conversation is cleared. - Martin Brown

If you omit the TOP 1 clause in the RECEIVE statement then it will receive all messages that meet the criteria, or setting it to a high number will allow you to clear the backlog in managable chunks.

The trick will be to 'blackhole' the messages so the result set isn't returned to the client.

respondido 08 nov., 11:16

Though this is the best answer I have found, it still isn't as quick as I would like. The trouble is that the RECEIVE statment only gets one conversation at a time regardless of how big you make the TOP n clause. - Martin Brown

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.