SQL Server 2008中远程Service Broker实现

  上文:SQL Server 2008中Service Broker基础应用(上)、SQL Server 2008中Service Broker基础应用(下)

  演示了在同一个SQL Server实例的不同数据库之间实现Service Broker,其实,更常见的是在不同的SQL Server实例之间进行通信,本文将通过实例演示如何进行Service Broker远程通信。

  以下是实现远程Service Broker的基本步骤:

  一、启用传输安全

  二、启用对话安全

  三、创建路由

  四、创建远程服务绑定

  下图显示的是两个 SQL Server 实例间的 Service Broker 网络通信的高级视图。

邀月工作室

  准备工作:

邀月工作室

/************************************************************/
------远程Service Broker
--
---- 3w@live.cn
--
---源服务器实例,在本例中为ap4/agroNET09
USE master
GO
-- Enable Service Broker for the database
ALTER DATABASE BookStore SET ENABLE_BROKER
GO
ALTER DATABASE BookStore SET TRUSTWORTHY ON
GO

USE BookStore
GO
-- Create the messages
CREATE MESSAGE TYPE [//SackConsulting/SendBookOrder]
VALIDATION
= WELL_FORMED_XML
GO
CREATE MESSAGE TYPE [//SackConsulting/BookOrderReceived]
VALIDATION
= WELL_FORMED_XML
GO

-- Create the contract
CREATE CONTRACT
[//SackConsulting/BookOrderContract]
(
[//SackConsulting/SendBookOrder]
SENT
BY INITIATOR,
[//SackConsulting/BookOrderReceived]
SENT
BY TARGET
)
GO

-- Create the queue
CREATE QUEUE BookStoreQueue
WITH STATUS=ON
GO

-- Create the service
CREATE SERVICE [//SackConsulting/BookOrderService]
ON QUEUE dbo.BookStoreQueue
(
[//SackConsulting/BookOrderContract])
GO

-----目标服务器实例,在本例中为ap2/agroNETserver
USE master
GO
IF NOT EXISTS (SELECT name
FROM sys.databases
WHERE name = 'BookDistribution')
CREATE DATABASE BookDistribution
GO

-- Enable Service Broker for the database
ALTER DATABASE BookDistribution SET ENABLE_BROKER
GO
ALTER DATABASE BookDistribution SET TRUSTWORTHY ON
GO

USE BookDistribution
GO
-- Create the messages
CREATE MESSAGE TYPE [//SackConsulting/SendBookOrder]
VALIDATION
= WELL_FORMED_XML
GO
CREATE MESSAGE TYPE [//SackConsulting/BookOrderReceived]
VALIDATION
= WELL_FORMED_XML
GO

-- Create the contract
CREATE CONTRACT
[//SackConsulting/BookOrderContract]
(
[//SackConsulting/SendBookOrder]
SENT
BY INITIATOR,
[//SackConsulting/BookOrderReceived]
SENT
BY TARGET
)
GO

-- Create the queue
CREATE QUEUE BookDistributionQueue
WITH STATUS=ON
GO

-- Create the service
CREATE SERVICE [//SackConsulting/BookDistributionService]
ON QUEUE dbo.BookDistributionQueue
(
[//SackConsulting/BookOrderContract])
GO

it知识库SQL Server 2008中远程Service Broker实现,转载需保留来源!

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。