Hi there. I have some troubles with SB. I created stored procedure and the all SB part, however the message appears in the queue but the procedure is executed only sometimes. It executed the first time and executed after some times later. What is wrong?
The code I use.
CREATE PROCEDURE dbo.sb_test AS select 'abrakadabra' DECLARE @h UNIQUEIDENTIFIER; DECLARE @messageTypeName SYSNAME; DECLARE @payload VARBINARY(MAX); WAITFOR(RECEIVE TOP(1) @h = conversation_handle, @messageTypeName = message_type_name, @payload = message_body FROM SBReceiveQueue), TIMEOUT 1000; INSERT INTO test(a) values(GETDATE()); GO
There is the code for SB part:
-- Create Message Type CREATE MESSAGE TYPE SBMessage VALIDATION = NONE GO -- Create Contract CREATE CONTRACT SBContract (SBMessage SENT BY INITIATOR) GO -- Create Send Queue alter QUEUE SBSendQueue WITH STATUS=ON, ACTIVATION ( PROCEDURE_NAME = dbo.sb_test, MAX_QUEUE_READERS = 1, EXECUTE AS SELF ) ; GO -- Create Receive Queue CREATE QUEUE SBReceiveQueue GO -- Create Send Service on Send Queue CREATE SERVICE SBSendService ON QUEUE SBSendQueue (SBContract) GO -- Create Receive Service on Recieve Queue CREATE SERVICE SBReceiveService ON QUEUE SBReceiveQueue (SBContract) GO -- Begin Dialog using service on contract DECLARE @SBDialog uniqueidentifier DECLARE @Message NVARCHAR(128) BEGIN DIALOG CONVERSATION @SBDialog FROM SERVICE SBSendService TO SERVICE 'SBReceiveService' ON CONTRACT SBContract WITH ENCRYPTION = OFF SET @Message = N'AAAAAAAAAAA'; -- CAST(GETDATE() AS VARCHAR); SEND ON CONVERSATION @SBDialog MESSAGE TYPE SBMessage (@Message) GO