SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


An Introduction to the Service Broker


An Introduction to the Service Broker

Author
Message
Srinivas Sampath
Srinivas Sampath
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 1

First off, I apologize for not responding to this thread earlier. I did not have an account at the forum and recently created one.

Not sure if any commercial scale applications have yet been developed using Service Broker, but I remember Roger Walter writing a few articles about the same and also delivering a few webcasts.

Here is one article about some use cases: http://msdn.microsoft.com/sql/archive/default.aspx?pull=/library/en-us/dnsql90/html/sql2k5_SrvBrk.asp



HTH,
Srinivas Sampath
Blog: http://blogs.sqlxml.org/srinivassampath
Srinivas Sampath
Srinivas Sampath
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 1

First off, I apologize for not responding to this thread earlier. I did not have an account at the forum and recently created one.

Service Broker messages are always sent to a service. Each service is associated with a queue and each queue can have an activation procedure that wakes up when messages arrive at the queue. You can also specify the maximum number of activation procedures that Service Broker can instantiate for the queue.



HTH,
Srinivas Sampath
Blog: http://blogs.sqlxml.org/srinivassampath
Srinivas Sampath
Srinivas Sampath
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 1

First off, I apologize for not responding to this thread earlier. I did not have an account at the forum and recently created one.

Service Broker can basically be used to achieve asynchronous semantics in the database. In your case, the application tier receives messages from an external source and if you are not using transactional messaging in MSMQ, the performance of SSB and MSMQ is comparable. Also, in your case, if the application tier is load-balanced, you will have multiple Q's doing the job. I would not recommend replacing this solution with SSB because, if you need to do some pre-processing of the Q before executing the SP, then you cannot do it. Also, by using MSMQ in this case, you can have other applications that can also drain the Q.

SSB is largely for writing reliable, asynchronous, message oriented database applications.



HTH,
Srinivas Sampath
Blog: http://blogs.sqlxml.org/srinivassampath
Kuido Külm
Kuido Külm
SSC Veteran
SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)

Group: General Forum Members
Points: 203 Visits: 43
I test this script on JuneCTP2005 SQL2005, but
RECEIVE CONVERT(NVARCHAR(max), message_body) AS message
FROM ReceiverQueue

or
SELECT CONVERT(NVARCHAR(max), message_body) AS message
FROM ReceiverQueue

gives nothing
Must the Sender and Receiver be different computers ?
Srinivas Sampath
Srinivas Sampath
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 1

First check if the ReceiverQueue itself has any message. If not, check the sys.transmission_queue to see if any errors are logged. One other post that I made had a user with a similar problem and the sys.transmission_queue had a message indicating an error about a missing database master key. If you see a similar error, you can solve it using the method that I've outlined in: http://blogs.sqlxml.org/srinivassampath/archive/2005/06/19/3457.aspx



HTH,
Srinivas Sampath
Blog: http://blogs.sqlxml.org/srinivassampath
steph-265477
steph-265477
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 1

Hello, great article, compact & clear. On my june CTP version, it didn't seem to work without the following change (maybe update the article ? )

DECLARE @conversationHandle UNIQUEIDENTIFIER
DECLARE @message NVARCHAR(100)

BEGIN
BEGIN TRANSACTION;
BEGIN DIALOG @conversationHandle
FROM SERVICE Sender
TO SERVICE 'Receiver'
ON CONTRACT HelloContract WITH ENCRYPTION=OFF, LIFETIME= 600;
-- Send a message on the conversation
SET @message = N'Hello, World';
SEND ON CONVERSATION @conversationHandle
MESSAGE TYPE HelloMessage (@message)
COMMIT TRANSACTION
END
GO

regards,

steph


bobzigon
bobzigon
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 1

Hello

I too am having problems getting this sample to work.

I created a db called TestDb.

I then pasted the sample service broker code (with your ENCRYPTION change)

into the mgmt studio. I modified the USE statement at the top.

There is never anything in the ReceiverQueue.

Everyone tries their sample code against the AdventureWorks db. I suspect that

db has some property set that we are not being told about.

Could you try the sample code after you create a new database.

Thanks.





Shafiq Muhammad
Shafiq Muhammad
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 34
Hi,

I tried your example but could not able to receive the message back. Pelase guide what I am doing wrong. Receive statement does not return any data back.

USE master;
GO

CREATE ENDPOINT BrokerEndpoint
STATE = STARTED
AS TCP ( LISTENER_PORT = 4037 )
FOR SERVICE_BROKER ( AUTHENTICATION = WINDOWS ) ;

Go
Use MySampleDB
Go
Create MESSAGE TYPE HelloMessage VALIDATION = None
GO
Create CONTRACT HelloContract ( HelloMessage SENT BY INITIATOR )
GO
Create Queue SenderQueue
GO
Create QUEUE ReceiverQueue
GO
Create Service Sender ON QUEUE SenderQueue
GO
Create Service Receiver ON QUEUE ReceiverQueue (HelloContract)
GO
DECLARE @conversationHandle UNIQUEIDENTIFIER
DECLARE @message nvarchar(100)
Begin
Begin Transaction;
Begin Dialog @conversationHandle
From Service Sender
TO Service 'Receiver'
ON CONTRACT HelloContract
Set @Message = N'Hellow, World';
Send ON Conversation @conversationHandle MESSAGE TYPE HelloMessage (@message)
Commit Transaction
End
Go

Receive Convert(Nvarchar(max),message_body) as message
From ReceiverQueue
GO
Select * from SenderQueue
Select * from ReceiverQueue
Select * from dbo.ServiceBrokerQueue

SQL-DBA
SQL-DBA
Old Hand
Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)Old Hand (385 reputation)

Group: General Forum Members
Points: 385 Visits: 462

hbatra -

I have just developed a C# app that does exactly what you explained (ie, writes from an MSMQ queue to a SQL Server table). Do you mind sharing how you run this app? As a scheduled task, a job in SQL Server, a service??? Just wondering. Thanks.

Steve


espasojevic
espasojevic
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 124

Nice article, but I'm not getting anything when I execute posted code.

Does anybody have an idea why?

Thanks





Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search