
Implementing Dynamic Routing
Most of the work involved in implementing dynamic routing is determining the address for the service name. You use whatever technique is appropriate for your application.
The responsibilities of the application for the Broker Configuration Notice service are simple. The application reads a MissingRoute message from the queue. If the application can determine the address for the service, the application creates a route for the service and then ends the conversation. How the application determines the address depends on the specific needs of your environment. For example, the application may consult an external service, run a query in another database, or produce a route to a Service Broker configured for message forwarding. However, if the application cannot determine the address for the service, the application ends the conversation with an error.
Notice that, in either case, the application that implements the Broker Configuration Notice service ends the conversation. Service Broker sends one MissingRoute message at a time for a specific service, regardless of the number of conversations to the service. Further, Service Broker uses the largest possible time-out for requests to the Broker Configuration service. Therefore if the Broker Configuration service does not end the conversation, Service Broker does not create a new request to the service. If the Broker Configuration service did not create a route, or the lifetime of the route that the service created expires, messages to the service will remain delayed until the conversation lifetime expires.