In most circumstances, an administrator configures routing information for Service Broker applications through the CREATE ROUTE T-SQL statement. However, in some cases, it would be better to retrieve routing information dynamically at runtime. Maybe you want to call another Service Broker service or do a lookup in Active Directory. For these scenarios, Service Broker provides you with the ability to implement a configuration notice service.

With a Service Broker configuration notice service, Service Broker provides functionality that allows you to create applications that provide dynamic routing information to the Service Broker application. When Service Broker can’t find a route for a conversation, it checks the routing table for a service with the name [SQL/ServiceBroker/BrokerConfiguration]. If an entry exists for that service, Service Broker will create a new conversation with that service and send a message on the opened conversation requesting that a route be created.

When the conversation with the [SQL/ServiceBroker/BrokerConfiguration] service ends,
Service Broker again attempts to route the message to the next hop along the route to the final destination. If no route exists at this point, Service Broker will mark all messages for the conversation as DELAYED. After a time-out period, Service Broker will again request a route from the [SQL/ ServiceBroker/BrokerConfiguration] service.

Implementing Dynamic Routing
Most of the work involved in implementing dynamic routing is in determining the address for the requested service name. Which approach you use to determine the address of the requested service is up to you: you can call another Service Broker service, you can call a web service, or you can start an Active Directory lookup through a managed stored procedure. It’s completely up to you and depends on your requirements.

The implementation of the configuration notice service is simple. The service program reads the received message from the associated queue. This message follows the [http:// SQL/ServiceBroker/BrokerConfigurationNotice/MissingRoute] message type that is part of the [ BrokerConfigurationNotice] contract. The retrieved message contains the service name, and the service program must provide the route to this specified service. If the service program is able to retrieve the requested routing information, the service program will create the route and finally end the conversation. If the service program isn’t able to determine the requested route, the service program must end the conversation with an error.

Notice that in each case, the service program that implements the configuration notice service has to end the conversation. Service Broker sends one [ ServiceBroker/BrokerConfigurationNotice/MissingRoute] message at a time for a specific service, regardless of the number of conversations to that service. Furthermore, Service Broker uses the largest possible time-out for requests to the configuration notice service. So, if the configuration notice service doesn’t end the conversation, Service Broker won’t create a new request to the service. If the configuration notice service doesn’t create a route, or if the lifetime of the route that the service created expires, a message to the service will remain delayed until the conversation lifetime expires.

Source of Information : Apress Pro SQL Server 2008 Service Broker


Subscribe to Developer Techno ?
Enter your email address:

Delivered by FeedBurner