Template Script: Service Broker\04 Tutorial Beginning a Conversation.sql

/* ************* Lesson 4: Beginning the Conversation ************* */
-- Switch to the InitiatorDB database

--Then, run it to switch context to the DBA database where you will initiate the conversation.

USE DBA;
GO
-- Start a conversation and send a request message

--Then, run it to begin a conversation and send a request message to the //DBA/SysMon/SysMonTargetService in the DBA. The code must be run in one block because a variable is used to pass a dialog handle from BEGIN DIALOG to the SEND statement. The batch runs the BEGIN DIALOG statement to begin the conversation, and then builds a request message. Then, it uses the dialog handle in a SEND statement to send the request message on that conversation. The last SELECT statement just displays the text of the message that was sent.

DECLARE @InitDlgHandle UNIQUEIDENTIFIER;
DECLARE @RequestMsg NVARCHAR(100);

BEGIN TRANSACTION;

BEGIN DIALOG @InitDlgHandle
     FROM SERVICE [//DBA/SysMon/SysMonInitiatorService]
     TO SERVICE N'//DBA/SysMon/SysMonTargetService'
     ON CONTRACT [//DBA/SysMon/SysMonContract]
     WITH
         ENCRYPTION = OFF;

SELECT @RequestMsg = N'' + @@SERVERNAME + '';

SEND ON CONVERSATION @InitDlgHandle
     MESSAGE TYPE [//DBA/SysMon/SysMonRequestMessage]
     (@RequestMsg);

SELECT @RequestMsg AS SentRequestMsg;

COMMIT TRANSACTION;
GO


SELECT * FROM sys.transmission_queue
SELECT * FROM sys.conversation_endpoints

SELECT  *
FROM    sys.services WHERE name = '//DBA/SysMon/SysMonTargetService'

SELECT * FROM sys.service_contracts WHERE name = '//DBA/SysMon/SysMonContract'


-- Connection handshake failed. The login 'FIRSTAMDATA\FACL-SQL06SVC' does not have CONNECT permission on the endpoint. State 84.

Description for Template Script: Service Broker\04 Tutorial Beginning a Conversation.sql

Todo
Site Map | Printable View | © 2008 - 2012 NuRoN Consulting, INC | Powered by mojoPortal | HTML 5 | CSS | Original design by Andreas Viklund
Share This Using Popular Bookmarking Services