SQL Server 2005 Beta 2 Service Broker: Create Route

SQL Server 2005 Beta 2 Service Broker: Create Route

 

Posted by: Rickie Lee (www.cnblogs.com/rickie)

Date: Apr. 2005

Following the previous post, A simple tutorial on SQL Server 2005 Beta 2 Service Broker, this post will handle how to send messages to and from in the different Database or SQL Server.

 

1. Create a new route to the routing table for the current database (initiator)

For outgoing messages, Service Broker determines routing by checking the routing table in the local database.

For example,

Use [Initiator DatabaseName]

CREATE ROUTE HelloRoute

    WITH

    SERVICE_NAME = 'SendingService',

    BROKER_INSTANCE = 'a727462b-52e7-4405-9eee-d19923729790',

    ADDRESS = 'LOCAL' ;

 

The broker_instance parameter must be the broker instance identifier for the remote database, which can be obtained by running the following query in the selected database:

Use [Remote DatabaseName]

SELECT service_broker_guid

FROM sys.databases

WHERE database_id = DB_ID()

 

2. Create Target Service in the remote database

In order for a message to be accepted at the target Endpoint’s service, three conditions must be satisfied that pertain to the Message Type:

(1) The initiator and target’s Message Type names must be exactly the same;

(2) The message must pass validation against its message body (the type of data it contains);

(3) The message Type used must be allowed by the Dialog conversation’s assigned Contract.

For example,

Use [Remote DatabaseName]

 

Create Message Type XMLMessage

Validation = WELL_FORMED_XML

 

Create Contract XMLContract

(XMLMessage Sent by ANY)

 

Create Queue ReceivingQueue With Status=ON, Retention=OFF

 

Create Service ReceivingService On Queue ReceivingQueue

(XMLContract)

 

3. Send message at the initiator service

Well, we know the initiator side must also contains all necessary Service Broker types, such as Message Type, Contract, Queue and Service, etc.

For example,

Declare @handle uniqueidentifier

Begin Dialog Conversation @handle

From Service SendingService

To Service 'ReceivingService'

On Contract XMLContract;

 

Send on Conversation @handle

Message Type XMLMessage

('<hello>Welcome to Rickie Lee''s blog, www.cnblogs.com/rickie</hello>');

 

End Conversation @handle with cleanup;

 

4. Receive message at the target side

Let’s check if the target queue has received the message.

For example,

Select * From ReceivingQueue

Select Cast(message_body as XML) From ReceivingQueue

-- Receive message from target queue

Receive Cast(message_body as XML) From ReceivingQueue

 

References:

1. A First Look at SQL Server 2005 Service Broker, Roger Wolter, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql90/html/sqlsvcbroker.asp?frame=true

2. Michael G., Service Broker Architecture, http://www.dotnetfun.com/articles/sql/sql2005/SQL2005ServiceBrokerBasicArchitecture.aspx

3. Mike Taulty’s Weblog, SQL Server 2005 Service Broker & WSE 2.0, http://mtaulty.com/blog/archive/2005/02/14/1484.aspx

 

 

posted @   Rickie  阅读(1484)  评论(2编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示