Service Broker
Service Broker 是一种消息传递框架,可用于创建本机数据库内面向服务的应用程序。 与在查询生命周期期间不断从表中读取数据的经典查询处理功能不同,面向服务的应用程序中提供可交换消息的数据库服务。 每个服务都有一个队列,消息在处理之前都排在队列中。
*
每个 Service Broker 会话都有两个端点:会话发起方和目标。您将执行下列任务:
● 为目标创建一个服务和队列,并为发起方创建一个服务和队列。
● 创建请求消息类型和答复消息类型。
● 创建约定,指定请求消息从发起方传递到目标并且答复消息从目标传递到发起方。
然后执行一个简单会话:
● 启动会话。
● 从发起方向目标发送一个请求。
● 在目标处接收请求并将答复发送到发起方。
● 在发起方处接收答复。
● 结束会话。
Broker具备的基本要素:message type,contract,queue,service
*
MESSAGE TYPE(消息类型)
*
*
CONTRACT(规范)
*
*
QUEUE(队列)
*
*
SERVICE(服务)
*
*
*
*
创建服务
*
*
发送消息
*
*
*
处理消息
*
*
*
启用Service Broker
alter database [数据库名称] set new_broker with rollback immediate
alter database [数据库名称] set enable_broker
--检测是否已经启用ServiceBroker【1表示已经启用 0表示没有启用】
select databasepropertyex ('数据库名称','IsBrokerEnabled')
查询
select name,is_broker_enabled from sys.databases where name = '数据库名称'
禁用Service Broker
alter database [数据库名称] set disable_broker
查看服务和队列
select s.name, q.name
from sys.services as s
join sys.service_queues as q on s.service_queue_id = q.object_id
查看队列使用的内部表的名称
select q.name as QueueName, i.name as InternalName
from sys.service_queues as q
join sys.internal_tables as i on q.object_id = i.parent_object_id
The server principal "sa" is not able to access the database "test" under the current security context 错误,权限问题
alter database [数据库名称1] set trustworthy on;
alter database [数据库名称2] set trustworthy on;
alter database [数据库名称3] set trustworthy on;
alter database [数据库名称4] set trustworthy on;
alter database [数据库名称5] set trustworthy on;
alter database [数据库名称6] set trustworthy on;
exec sp_changedbowner 'sa'
The SELECT permission was denied on the object '表名称', database '数据库名称', schema 'dbo'. 错误
GRANT SELECT TO public
*
select * from sys.conversation_endpoints order by security_timestamp desc
select * from sys.service_queue_usages
select * from sys.dm_broker_connections
select * from sys.dm_broker_activated_tasks
select * from sys.dm_broker_queue_monitors
*
select * from sys.dm_os_performance_counters
select * from sys.dm_os_performance_counters where object_name='SQLServer:Broker Statistics'
select * from sys.dm_os_performance_counters where object_name='SQLServer:Broker/DBM Transport'
select * from sys.dm_os_performance_counters where object_name='SQLServer:Broker Activation'
select * from sys.dm_os_performance_counters where object_name='SQLServer:Broker TO Statistics'
*
*
*
*
*