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

Orphaned Conversation Handle Remains After Ending the Conversation From Both Sides

$
0
0

I am try to implement a simple proof-of-concept of SB, and I am having trouble understanding why conversation handles are building up despite the fact that I am not implementing the "fire-and-forget" anti-pattern and I am ending the conversation twice.  The TSQL below can be used to demonstrate the issue.  Any assistance or advice would be greatly appreciated.

use master
GO
IF EXISTS(select * from sys.databases where name = 'TestServiceBroker')
	DROP database TestServiceBroker
GO
CREATE DATABASE TestServiceBroker
ALTER DATABASE TestServiceBroker SET ENABLE_BROKER
GO
use TestServiceBroker
GO
CREATE MESSAGE TYPE TestMessage VALIDATION = NONE
CREATE CONTRACT TestMessageContract (TestMessage SENT BY INITIATOR)
CREATE QUEUE TargetQueue
CREATE QUEUE InitiatorQueue
CREATE SERVICE [TargetService] ON QUEUE TargetQueue ([TestMessageContract])
CREATE SERVICE [InitiatorService] ON QUEUE InitiatorQueue ([TestMessageContract])
GO

/*Start a dialog*/
DECLARE @dialog_handle uniqueidentifier;

BEGIN DIALOG CONVERSATION @dialog_handle
   FROM SERVICE [InitiatorService]
   TO SERVICE 'TargetService'
   ON CONTRACT [TestMessageContract]
   WITH ENCRYPTION = OFF;

/*Send a message on that dialog*/
SEND ON CONVERSATION @dialog_handle
	MESSAGE TYPE TestMessage;
GO

/*Receive the message on the target*/
DECLARE @dialog_handle uniqueidentifier;
RECEIVE top(1) @dialog_handle = conversation_handle FROM TargetQueue;

/*End the dialog from target*/
END CONVERSATION @dialog_handle;
GO

/*Receive the end dialog request on the initiator*/
DECLARE @dialog_handle uniqueidentifier;
RECEIVE top(1) @dialog_handle = conversation_handle FROM InitiatorQueue;	

/*End the dialog from initiator*/
END CONVERSATION @dialog_handle;
GO

/*The dialog should now be closed cleanly.  Why is there still an endpoint listed here???!!!*/
select conversation_handle as 'Orphaned Conversation Handle'
from sys.conversation_endpoints;


Viewing all articles
Browse latest Browse all 461

Trending Articles