Service Broker Application Queue Disable Event

2019-07-21 15:42发布

问题:

I am trying an option BROKER_QUEUE_DISABLED in EVENT NOTIFICATION it seems it is not properly generating a Broker Queue disabled event. Can some one please validate the script which I created? (see below)

Script:

CREATE QUEUE NotifyQueue

GO

CREATE

SERVICE NotifyService

ON

QUEUE NotifyQueue

[http://schemas.microsoft.com/SQL/Notifications/PostEventNotification]);


GO

CREATE ROUTE NotifyRoute
 WITH SERVICE_NAME = 'NotifyService',
 ADDRESS = 'LOCAL';
 GO

CREATE

EVENT NOTIFICATION [CHS_QueueDisabledNotif] 

       ON QUEUE [CHS_Change_Queue] WITH FAN_IN 

       FOR BROKER_QUEUE_DISABLED

       TO SERVICE 'NotifyService', 'current database'



--Testing

--Try Disabling Application Queue

ALTER QUEUE dbo.CHS_Change_Queue WITH STATUS = OFF

SELECT * FROM NotifyQueue

回答1:

I found an answer to my question :)

SQL engine will not generate disable event if we manually turned off the queue. It will generate only if any error occurs in activation procedure. I added custom error in activation proc, something like SELECT 1/0 then SQL can generate Disable event.