SQL Server 2008 table change (insert/update/delete) notification push on broker

南笙酒味 提交于 2019-12-11 18:51:51

问题


I have a rather complex and large database with about 3000+ objects (tables/triggers/sps combined). I inherited this DB and restructuring it is probably 3-4 years away. meanwhile, I need to implement a pub sub feature for any insert/update/delete on these tables. Given number of tables and existing queries probably query notification (and SQL Dependency) will not work. What I am looking for is a way to push the changes (what changed in table - like records PK and table name) on the service broker so I can use external activator to then retrieve change,and then use my custom pub sub from that point onwards.

I have pretty much all the ducks lined up except for the way to push change notification on service broker.

Any help/pointers are appreciated. Thanks. N M PS. I did look around for similar postings and did come across a few however, MSDN articles they referred to seem to have all removed - not sure what's going on on MSDN site.


回答1:


For external activator look at Microsoft SQL Server 2008 Feature Pack- "Microsoft SQL Server 2008 R2 Service Broker External Activator".

For console application (that processes messages) great idea is to drop an eye in codeplex. There is good examples.

To put event notification (notifications, that will be used by external activator service) code looks something like this:

Create Queue ExternalActivatorQueue;
Create Service ExternalActivatorService On Queue ExternalActivatorQueue
([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification])

Create Event Notification NotifyExternalActivator
On Queue dbo.ProcessQueue
For QUEUE_ACTIVATION
To Service 'ExternalActivatorService', 'current database'

To send message in the queue:

    Declare @h UniqueIdentifier;
    Declare @x xml = '<tag/>';
    Begin Dialog Conversation @h
    From Service MyTableService
        To Service 'ProcessService'
    With Encryption = OFF;

    Send On Conversation @h(@x)

All steps i done to make it work is here, but just in Latvian :). There actually is almost what you need (trigger that sends messages when data are inserted in table..).



来源:https://stackoverflow.com/questions/10603041/sql-server-2008-table-change-insert-update-delete-notification-push-on-broker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!