我需要获得 SSB 外部激活才能从 db 触发器启动 exe。借助网络上可用的少量信息,我设法使几乎所有东西都能完美运行。我可以向队列发送消息,并且可以使用持续轮询数据库的 C# 应用程序从队列中读取消息。但我需要外部激活器来实际启动我的 exe。这是为了工作,我被困住了,所以非常感谢任何帮助!
外部激活器日志文件:这里
外部激活器配置文件:这里
队列状态(图片):这里
谢谢!
编辑:SQL代码:
ALTER DATABASE AdventureWorks2012 SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
创建消息类型 [requestMessageType] 验证 = WELL_FORMED_XML
创建消息类型 [responseMessageType] 验证 = WELL_FORMED_XML
创建合同 [smtContract] ( [requestMessageType] SENT BY INITIATOR, [responseMessageType] SENT BY TARGET )
CREATE QUEUE InitiatorQueue WITH STATUS = ON
创建队列 TargetQueue WITH STATUS = ON
在队列 InitiatorQueue ( [smtContract] ) 上创建服务 InitiatorService
在队列 TargetQueue ( [smtContract] ) 上创建服务 TargetService
CREATE QUEUE ExternalActivatorQueue WITH STATUS = ON
在队列 ExternalActivatorQueue 上创建服务 ExternalActivatorService ([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification])
CREATE EVENT NOTIFICATION EventNotificationTargetQueue ON QUEUE TargetQueue FOR QUEUE_ACTIVATION TO SERVICE 'ExternalActivatorService', 'current database';
CREATE TABLE [Order] (ID int identity(1000,1) NOT NULL, Amount MONEY NOT NULL)
-- 触发器会将消息添加到 ImportQueue Create TRIGGER OnOrderInserted ON [Order] FOR INSERT AS BEGIN BEGIN TRANSACTION; DECLARE @ch UNIQUEIDENTIFIER DECLARE @messageBody NVARCHAR(MAX);
BEGIN DIALOG CONVERSATION @ch
FROM SERVICE [InitiatorService]
TO SERVICE 'TargetService'
ON CONTRACT [smtContract]
WITH ENCRYPTION = OFF;
-- Construct the request message
SET @messageBody = (SELECT ID, Amount FROM [Order] FOR XML AUTO, ELEMENTS);
-- Send the message to the TargetService
;SEND ON CONVERSATION @ch
MESSAGE TYPE [requestMessageType] (@messageBody);
COMMIT;
结束
将数据库授权::AdventureWorks2012 更改为 [sa];
ALTER QUEUE InitiatorQueue WITH ACTIVATION (PROCEDURE_NAME = ProcessResponseMessages, STATUS = ON, MAX_QUEUE_READERS = 1, EXECUTE AS OWNER)