Quantcast
Channel: SQL Service Broker forum
Viewing all articles
Browse latest Browse all 461

Activation Stored Procedure Not Firing

$
0
0

I am using SQL Server 2008 SP1.  This is my first attempt to understand using the service broker. I have the following script to create the necessary message type, contract, queue and service.

CREATE MESSAGE TYPE [AddToQueue]
VALIDATION = WELL_FORMED_XML
GO

CREATE CONTRACT [QueueContract] (
	[AddToQueue] SENT BY INITIATOR
)
GO

CREATE QUEUE ReportingQueue
WITH
	STATUS = ON,
	RETENTION = OFF,
	ACTIVATION (
		STATUS = ON,
		PROCEDURE_NAME = dbo.RUN_REPORT,
		MAX_QUEUE_READERS = 5,
		EXECUTE AS SELF
	)
GO

CREATE SERVICE [ReportingService]
ON QUEUE dbo.ReportingQueue([QueueContract])
GO

I am using the following script to add a message to the queue.  When I have retention on I can see that the message is being added to the queue just fine.  The stored procedure RUN_REPORT is designed to insert data into a table and read the message.  It never inserts any records into the table which tells me it is never being called, even though the message disappears from the queue.

CREATE PROCEDURE [dbo].[RUN_REPORT]
AS
SET NOCOUNT ON

DECLARE @ConversationHandle UNIQUEIDENTIFIER
DECLARE @MessageType NVARCHAR(256)
DECLARE @MessageBody XML
DECLARE @ResponseMessage XML

BEGIN TRY
    INSERT INTO RECEIVED (processed) VALUES (1)

    WAITFOR(RECEIVE TOP(1)
        @ConversationHandle = conversation_handle,
        @MessageType = message_type_name,
        @MessageBody = CAST(message_body AS XML)
    FROM ReportingQueue), TIMEOUT 1000

    SELECT @MessageType
END TRY
BEGIN CATCH
    SELECT ERROR_MESSAGE()
    ROLLBACK TRANSACTION
END CATCH


Viewing all articles
Browse latest Browse all 461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>