Hi,
I am new to SQL Service Broker
and am currently trying to develop a POC.
I need to call a web service when a insert is made on a table. I have setup 3 queues and 3 services with associated message types (code below).
I have had some success after running the code below and performing an insert I see the messages appear on the following queues:
TargetPostQueue
InitiatorPostQueue
NotificationPostQueue
Then I start the Service Broker External Activator and the message is taken off NotificationPostQueue as expected and passed to my dummy console app that just prints out the args passed; for now.
The problem is after this no other messages appear on the NotificationPostQueue no matter how many inserts I do.
I see them appear on the TargetPost and InitiatorPost queues but nothing moves to the NotificationPostQueue. I'm sure this has something to do with me not ending the conversation but am unsure. What I can do when this happens, for now, is drop and delete the
database then recreate it to give me one more go but it's taking too long.
Code for creating queue's and services
-- Create message types
CREATE MESSAGE TYPE [//MetLife/BPA/RequestPostMessage] VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE [//MetLife/BPA/ReplyPostMessage] VALIDATION = WELL_FORMED_XML;
GO
-- Create contract
CREATE CONTRACT [//MetLife/BPA/PostContract]
([//MetLife/BPA/RequestPostMessage] SENT BY INITIATOR,
[//MetLife/BPA/ReplyPostMessage] SENT BY TARGET
);
GO
-- Create target queue and service
CREATE QUEUE TargetPostQueue WITH RETENTION = ON;
CREATE SERVICE [//MetLife/BPA/TargetPostService]
ON QUEUE TargetPostQueue([//MetLife/BPA/PostContract]);
GO
-- Create the initiator queue and service
CREATE QUEUE InitiatorPostQueue WITH RETENTION = ON;
CREATE SERVICE [//MetLife/BPA/InitiatorPostService]
ON QUEUE InitiatorPostQueue([//MetLife/BPA/PostContract]);
GO
-- Create a notification for External Activator
CREATE QUEUE NotificationPostQueue
CREATE SERVICE [//MetLife/BPA/NotificationPostService]
ON QUEUE NotificationPostQueue([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification])
CREATE EVENT NOTIFICATION EventQueueActivation
ON QUEUE [TargetPostQueue]
FOR QUEUE_ACTIVATION
TO SERVICE '//MetLife/BPA/NotificationPostService', 'current database';
GO
Code for Trigger and Test Table
CREATE TABLE [Policies]
(
PolicyId INT NOT NULL IDENTITY(1,1),
Amount MONEY NOT NULL,
BrokerName NVARCHAR(50) NOT NULL
)
GO
-- Trigger will add a message into a ImportQueue
CREATE TRIGGER OnPolicyInserted ON [Policies] FOR INSERT
AS
BEGIN
BEGIN TRANSACTION;
DECLARE @ch UNIQUEIDENTIFIER
%2