Is routing messages to the msdb SQL database requi

2019-09-02 06:54发布

问题:

In the examples I can find of communicating between server instances using SQL Server Service Broker (here and here), routes are created to the MSDB database which is one of the system databases. For example

use msdb;
go

create route [sender]
 with service_name = ‘sender’,
 address = ‘local’;
go

Why would I not create the route in the database that has the rest of the Service Broker objects such as message types and services? Is this how a production environment should do it?

回答1:

Messages received from network are routed inside the SQL Server instance according to routing rules of msdb. This is by convention, the routing rules have to be declared somewhere and we picked msdb. Normally msdb contains the AutoCreatedLocal route which makes all services, in any database, addressable. One can remove this global route and add explicit routes for some services, which will make only those services addressable. I didn't see this done in practice, though. Most times the AutoCreatedLocal route is left in place an will handle all incoming traffic.

Note that msdb routes are used for forwarding scenarios where a machine accepts messages from one network and route them onto another one.