Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 What are the uses/benefits of SERVICE BROKER

Author  Topic 

missMac
Posting Yak Master

124 Posts

Posted - 2009-10-23 : 17:26:59
Hello guys

I have been reading up on service broker.ie reliable message communications to run stored procedures

But why do i need service broker and does anyone have examples apart from db backups in express ???

thanks

MM

missMac
Posting Yak Master

124 Posts

Posted - 2009-11-19 : 17:34:36
bump
Go to Top of Page

kbhere
Yak Posting Veteran

58 Posts

Posted - 2009-11-20 : 00:35:43
Service Broker is a feature in Microsoft SQL Server 2005, in which internal or external processes can send and receive guaranteed, asynchronous messages by using extensions to Transact-SQL Data Manipulation Language (DML). Messages can be sent to a queue in the same database as the sender, to another database in the same SQL Server instance, or to another SQL Server instance either on the same server or on a remote server.

Key concepts in Service Broker are queues, dialogs, conversation groups, and activation.

1.Queues

Service Broker uses queues to provide loose coupling between the message sender and the message receiver. The sender can use the SEND command to put a message in a queue and then continue on with the application, relying on Service Broker to ensure that the message reaches its destination.
Queues permit a lot of scheduling flexibility. For example, the sender can send out multiple messages for multiple receivers to process in parallel. The receivers might not process the messages until long after they were sent, but because incoming messages are queued, the receivers can process them at their own rate and the sender doesn't have to wait for the receivers to finish before continuing.

2.Dialogs

Service Broker implements dialogs, which are bidirectional streams of messages between two endpoints. All messages in a dialog are ordered, and dialog messages are always delivered in the order they are sent. The order is maintained across transactions, across input threads, across output threads, and across crashes and restarts. Some message systems ensure message order for the messages sent or received in a single transaction but not across multiple transactions, making Service Broker dialogs unique in this regard.Each message includes a conversation handle that uniquely identifies the dialog that is associated with it. For example, an order entry application might have dialogs open simultaneously with the shipping application, the inventory application, and the billing application. Because messages from each application have a unique conversation handle, it's easy to tell which application sent each message.

3.Conversation Groups

Service Broker provides a way of grouping all the dialogs that are used for a particular task.This method uses conversation groups. In our previous order entry example, all the dialogs associated with processing a particular order would be grouped into a single conversation group. The conversation group is implemented as a conversation group identifier, which is included with all messages in all dialogs contained in the conversation group. When a message is received from any of the dialogs in a conversation group, the conversation group is locked with a lock that is held by the receiving transaction. For the duration of the transaction, only the thread that holds the lock can receive messages from any of the dialogs in the conversation group. This makes our order entry application much easier to write because even though we use many threads for scalability, any particular order is only processed on one thread at a time. This means we don't have to make our application resilient to problems that are caused by the simultaneous processing of a single order on multiple threads.

4.Activation

The activation feature of Service Broker is used to specify a stored procedure that will handle messages destined for a particular service. When messages arrive for a service, Service Broker checks whether there is a stored procedure running that can process the messages. If there isn't a running message-processing stored procedure, Service Broker starts one. The stored procedure then processes messages until the queue is empty, after which it terminates. Moreover, if Service Broker determines that messages are arriving faster than the stored procedure can process them, it starts additional instances of the stored procedure until enough are running to keep up with the incoming messages (or until the configured maximum number is reached). This ensures that the right number of resources for processing incoming messages are always available.

You got it??

Balaji.K
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-30 : 05:00:37
quote:
Originally posted by kbhere

Service Broker is a feature in Microsoft SQL Server 2005, in which internal or external processes can send and receive guaranteed, asynchronous messages by using extensions to Transact-SQL Data Manipulation Language (DML). Messages can be sent to a queue in the same database as the sender, to another database in the same SQL Server instance, or to another SQL Server instance either on the same server or on a remote server.

Key concepts in Service Broker are queues, dialogs, conversation groups, and activation.

1.Queues

Service Broker uses queues to provide loose coupling between the message sender and the message receiver. The sender can use the SEND command to put a message in a queue and then continue on with the application, relying on Service Broker to ensure that the message reaches its destination.
Queues permit a lot of scheduling flexibility. For example, the sender can send out multiple messages for multiple receivers to process in parallel. The receivers might not process the messages until long after they were sent, but because incoming messages are queued, the receivers can process them at their own rate and the sender doesn't have to wait for the receivers to finish before continuing.

2.Dialogs

Service Broker implements dialogs, which are bidirectional streams of messages between two endpoints. All messages in a dialog are ordered, and dialog messages are always delivered in the order they are sent. The order is maintained across transactions, across input threads, across output threads, and across crashes and restarts. Some message systems ensure message order for the messages sent or received in a single transaction but not across multiple transactions, making Service Broker dialogs unique in this regard.Each message includes a conversation handle that uniquely identifies the dialog that is associated with it. For example, an order entry application might have dialogs open simultaneously with the shipping application, the inventory application, and the billing application. Because messages from each application have a unique conversation handle, it's easy to tell which application sent each message.

3.Conversation Groups

Service Broker provides a way of grouping all the dialogs that are used for a particular task.This method uses conversation groups. In our previous order entry example, all the dialogs associated with processing a particular order would be grouped into a single conversation group. The conversation group is implemented as a conversation group identifier, which is included with all messages in all dialogs contained in the conversation group. When a message is received from any of the dialogs in a conversation group, the conversation group is locked with a lock that is held by the receiving transaction. For the duration of the transaction, only the thread that holds the lock can receive messages from any of the dialogs in the conversation group. This makes our order entry application much easier to write because even though we use many threads for scalability, any particular order is only processed on one thread at a time. This means we don't have to make our application resilient to problems that are caused by the simultaneous processing of a single order on multiple threads.

4.Activation

The activation feature of Service Broker is used to specify a stored procedure that will handle messages destined for a particular service. When messages arrive for a service, Service Broker checks whether there is a stored procedure running that can process the messages. If there isn't a running message-processing stored procedure, Service Broker starts one. The stored procedure then processes messages until the queue is empty, after which it terminates. Moreover, if Service Broker determines that messages are arriving faster than the stored procedure can process them, it starts additional instances of the stored procedure until enough are running to keep up with the incoming messages (or until the configured maximum number is reached). This ensures that the right number of resources for processing incoming messages are always available.

You got it??

Balaji.K



When you give informations taken from other source you need to specify the link. The informations you posted are availalbe at http://msdn.microsoft.com/en-us/library/ms345108(SQL.90).aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kbhere
Yak Posting Veteran

58 Posts

Posted - 2009-11-30 : 08:35:22
Madhivanan,

FYI..

When i posted this reply i was new to this forum and also i dont know how to post the replies for these type of questions. But after few days i learnt new things in posting replies. Thereafter i started to provide the links. If possible, you can check those replies for which i have given the link address and confirm.

However, thanks for your belated advice. I will give much more attention in future regarding this.

Balaji.K
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-30 : 09:00:39
quote:
Originally posted by kbhere

Madhivanan,

FYI..

When i posted this reply i was new to this forum and also i dont know how to post the replies for these type of questions. But after few days i learnt new things in posting replies. Thereafter i started to provide the links. If possible, you can check those replies for which i have given the link address and confirm.

However, thanks for your belated advice. I will give much more attention in future regarding this.

Balaji.K



Ok. No problem

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

WoodHouse
Posting Yak Master

211 Posts

Posted - 2009-11-30 : 09:00:51
Hi Kbhere

If you really workaround something u have to post entire stuff its not an issue.
But the info things u just give the link.

Fine now you understand well.

Just see the Madhivanan, Peso,tkizer, X002548,Kristen,khtan,TG, etc.., replies. You will learn Lot.
Go to Top of Page
   

- Advertisement -