I've never used SSB before and is looking to implement this due to an issue we recently had with long running queries executing from a trigger.
I'm following the guide below. Looks OK when I run each code and I'm kind of following what is happening.
https://sqlperformance.com/2014/03/sql-performance/configuring-service-broker
Anyway, I wanted to test an email notification. So on the [ProcessingQueueActivation] SPROC, I inserted the lines below (send mail part):
IF @message_type_name = N'AsyncRequest'
BEGIN
-- Handle complex long processing here
-- For demonstration we'll pull the account number and send a reply back only
DECLARE @AccountNumber INT = @message_body.value('(AsyncRequest/AccountNumber)[1]', 'INT');
-- ADDED PART START
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'MYPRODILE',
@recipients = 'myname@mycompany.org',
@subject = 'BROKER TEST',
@body = @AccountNumber;
-- ADDED PART END
-- Build reply message and send back
DECLARE @reply_message_body XML = N'
' + CAST(@AccountNumber AS NVARCHAR(11)) + '
';
I tested it and I got the email when I run the script below.
EXECUTE dbo.SendBrokerMessage
@FromService = N'RequestService',
@ToService = N'ProcessingService',
@Contract = N'AsyncContract',
@MessageType = N'AsyncRequest',
@MessageBody = N'<AsyncRequest><AccountNumber>04</AccountNumber></AsyncRequest>';
EXECUTE dbo.ProcessingQueueActivation;
EXECUTE dbo.RequestQueueActivation;
However, when I turn on the AUTOMATE PROCESS (below), I don't get any email at all. I don't see any records on the [ProcessingQueue] and [RequestQueue] so I'm assuming it got processed.
-- Alter the processing queue to specify internal activation
ALTER QUEUE ProcessingQueue
WITH ACTIVATION
(
STATUS = ON,
PROCEDURE_NAME = dbo.ProcessingQueueActivation,
MAX_QUEUE_READERS = 10,
EXECUTE AS SELF
);
GO
-- Alter the request queue to specify internal activation
ALTER QUEUE RequestQueue
WITH ACTIVATION
(
STATUS = ON,
PROCEDURE_NAME = dbo.RequestQueueActivation,
MAX_QUEUE_READERS = 10,
EXECUTE AS SELF
);
GO
Any ideas?
TIA