SQL Server Service Borker 1

1、消息类型定义:

  消息类型,是信息交换的模板、create message type message_type_name validattion = well_formed_xml;

2、约定定义:

  约定,指示任务使用的消息 create contract contract_name (message_type_name sent by initiator |target | all [....]);

3、队列定义:

  队列是信息的集合: create queue queue_name with status = on;

4、服务定义:

  服务定义端口用来把消息绑定到一个或多个约定上 create service service_name on queue queue_name(contract_name_list);

例子:

create database bookstore;
create database bookdistribution;

----时间 执行者 目的

----2014-10-30 蒋乐 创建两个数据库用于测试 service broker!
go

use bookstore;

alter database bookstore
set enable_broker;

alter database bookstore
set trustworthy on;

create master key
encryption by password =‘123456‘;

----时间 执行者 目的

----2012-10-30 蒋乐 配制数据库的 3(enable_broker\trustworthy\master key) 个选项使它支持 service borker
go

use bookdistribution;

alter database bookdistribution
set enable_broker;

alter database bookdistribution
set trustworthy on;

create master key
encryption by password = ‘123456‘;

----时间 执行者 目的

----2012-10-30 蒋乐 配制数据库的 3(enable_broker\trustworthy\master key) 个选项使它支持 service borker

go

use bookstore;

create message type [send_to_distribution]
validation = well_formed_xml;

create message type [send_to_distribution_received]
validation = well_formed_xml;

create contract [send_to_distribution_contract](
[send_to_distribution] sent by initiator,
[send_to_distribution_received] sent by target);

----时间 执行者 目的

----2012-10-30 蒋乐 定义消息类型与约定、(注意在两个相互通信的数据库中
--要有一样的消息类型与约定才可以通信。
go

use bookdistribution;

create message type [send_to_distribution]
validation = well_formed_xml;

create message type [send_to_distribution_received]
validation = well_formed_xml;

create contract [send_to_distribution_contract](
[send_to_distribution] sent by initiator,
[send_to_distribution_received] sent by target);

----时间 执行者 目的

----2012-10-30 蒋乐 定义消息类型与约定。
go

use bookstore;

create queue [send_to_bookdistribution_queue]
with
status = on;

----时间 执行者 目的

----2012-10-30 蒋乐 定义队列
go

use bookdistribution;

create queue [send_to_bookdistribution_queueBookDistribution]
with
status = on;

----时间 执行者 目的

----2012-10-30 蒋乐 定义队列
go

use bookstore;

create service [send_to_distribution_service_bookstore]
on queue send_to_bookdistribution_queue(send_to_distribution_contract);

----时间 执行者 目的

----2012-10-30 蒋乐 定义服务
go

use bookdistribution

create service [send_to_distribution_service_bookdistribution]
on queue send_to_bookdistribution_queueBookDistribution(send_to_distribution_contract);

----时间 执行者 目的

----2012-10-30 蒋乐 定义服务
go

use bookstore;

declare @handle uniqueidentifier;
declare @message xml;

begin dialog conversation @handle
from service send_to_distribution_service_bookstore
to service ‘send_to_distribution_service_bookdistribution‘ -- ! _ ! -- :因为它定义在别的数据库中、所以不可以用名字。要用字符串。
on contract send_to_distribution_contract;

set @message = ‘<Person>11436101</Person>‘;

send on conversation @handle message type send_to_distribution
(@message);

----时间 执行者 目的

----2012-10-30 蒋乐 发送一个异步的消息
go

use bookdistribution;

select * from dbo.send_to_bookdistribution_queueBookDistribution;

----时间 执行者 目的

----2012-10-30 蒋乐 查看发送过来的消息
go

时间: 2024-08-17 22:47:21

SQL Server Service Borker 1的相关文章

The SQL Server Service Broker for the current database is not enabled

把一个数据恢复至另一个服务器上,出现了一个异常: The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported.  Please enable the Service Broker for this database if you wish to use notifications. 截图如下: 解决方法: 参

未启用当前数据库的 SQL Server Service Broker,请为此数据库启用 Service Broker

未启用当前数据库的 SQL Server Service Broker,因此查询通知不受支持.如果希望使用通知,请为此数据库启用 Service Broker, 我执行了下面语句解决了问题 ALTER DATABASE [数据库名称] SET NEW_BROKER WITH ROLLBACK IMMEDIATE;ALTER DATABASE [数据库名称] SET ENABLE_BROKER; 未启用当前数据库的 SQL Server Service Broker,请为此数据库启用 Servic

Reusing dialogs with a dialog pool--一个sql server service broker例子

一个sql server service broker例子 ----------------------------------- USE master GO -------------------------------------------------- -- Create demo database section -------------------------------------------------- IF EXISTS (SELECT name FROM sys.data

在Windows Server 2008 R2 Server中,连接其他服务器的数据库遇到“未启用当前数据库的 SQL Server Service Broker,因此查询通知不受支持。如果希望使用通知,请为此数据库启用 Service Broker ”

项目代码和数据库部署在不同的Windows Server 2008 R2 Server中,错误日志显示如下: "未启用当前数据库的 SQL Server Service Broker,因此查询通知不受支持.如果希望使用通知,请为此数据库启用 Service Broker." SQL Server Service Broker介绍: SQL Server Service Broker 为消息和队列应用程序提供 SQL Server 数据库引擎本机支持.这使开发人员可以轻松地创建使用数据库

sql server service broker中调用存储过程执行跨库操作,不管怎么设置都一直提示 服务器主体 &quot;sa&quot; 无法在当前安全上下文下访问数据库 &quot;dbname&quot;。

用sql server自带的消息队列service borker,调用存储过程中,执行了一个跨库的操作,先是用了一个用户,权限什么都给够了,但是一直提示 服务器主体 "user" 无法在当前安全上下文下访问数据库 "dbname". 想着是架构方面的问题,换sa还是不行.查到微软的一篇文章 提示需要开数据库的 ALTER DATABASE current_db SET TRUSTWORTHY ON 我把跨的那个库设置了还是不行.最后自己写测试代码,代码如下: cre

sql server Service Broker 相关查询

-- 查看传输队列中的消息 --如果尝试从队列中移除时,列将表明哪里出现了问题 select * from sys.transmission_queue -- 查看Service Broker 激活的存储过程 select * from sys.dm_broker_activated_tasks -- 查看数据库中的每个会话端点.会话端点代表Service Broker 会话的每一端. -- 会话端点视图state列显示会话的状态 select * from sys.conversation_e

未启用当前数据库的 SQL Server Service Broker,因此查询通知不受支持。如果希望使用通知,请为此数据库启用 Service Broker

昨晚遇到的这个问题,也知道Notifications service依赖底层的Service broker的.本以为只需要执行以下脚本对数据库启用Service broker即可. alter database DBNAME set enable_broker 但是,执行后,脚本一直处于执行状态,不以为然,正好在忙其它事情就没有查看运行结果,结果到今早一看,居然运行还没有结束.虽然是在一个生产数据库上执行的,数据库也只有30G的样子,但也不至于执行一个晚上也未结束,只好终止执行,使用 SELEC

错误:未启用当前数据库的SQL Server Service Broker,因此查询通知不受支持。如果希望使用通知,请为此数据库启用 Service Broker。

解决方法: 打开SQL Server,新建查询: ALTER DATABASE 数据库名 SET NEW_BROKER WITH ROLLBACK IMMEDIATE;ALTER DATABASE 数据库名 SET ENABLE_BROKER; 转自:http://www.cnblogs.com/Impulse/articles/5358379.html

SQL Server Service Broker 示例(转)

1.定义数据类型.协议和服务(发送服务和接收服务) USE master; GO ALTER DATABASE 目标数据库 SET ENABLE_BROKER; GO -- 如果上面的操作执行后,长时间无反应,有死机的嫌疑,尝试下面的语句. ALTER DATABASE 目标数据库 SET NEW_BROKER WITH ROLLBACK IMMEDIATE; GO ALTER DATABASE 目标数据库 SET ENABLE_BROKER; GO -- 创建 SayHelloMessage