Sunday, November 18, 2012

SERVICE BROKER TUTORIAL STEP BY STEP

Steps to create service broker application:

For creating service broker first step is we need to create master key


ALTER DATABASE [LABS] SET ENABLE_BROKER  --LABS is a sample databasename


For creating service broker second step is we need to create master key


CREATE MASTER KEY ENCRYPTION BY PASSWORD = '23987hxJ#KL95234nl0zBe';

If need to create key with encryption



ALTER MASTER KEY REGENERATE WITH ENCRYPTION BY PASSWORD = 'dsjdkflJ435907NnmM#sX003';

Next step is create message type



create message type awnewnotice validation=none

create message type awack validation=none;


create contract 


create contract newnoticecontract
authorization dbo
(awnewnotice sent by any,
awack sent by any)


create queue


create queue awnewnoticequeue

create queue awackqueue

create service

create service awnewnoticeservice
on queue awnewnoticequeue

create service awackservice
on queue awackqueue


Start conversion 

send conversion

declare @dialog_handle uniqueidentifier,@xmldata xml;

set @xmldata=(select * from sys.tables  for xml auto)

begin dialog @dialog_handle
from service awnewnoticeservice
to service 'awackservice'
on contract newnoticecontract;


send on conversation @dialog_handle
message type awnewnotice

select * from [dbo].[awnewnoticequeue]

 receive conversion

declare @dialog_handle uniqueidentifier,@xmldata xml;

set @xmldata=(select * from sys.tables  for xml auto);

Receive top (1) @dialog_handle=conversation_handle
from [awnewnoticequeue]

end conversation @dialog_handle

select @xmldata



No comments: