SQL Server 2005 Beta 2 Service Broker: Create Route

SQL Server 2005 Beta 2 Service Broker: Create Route

 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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

 

 

转载于:https://www.cnblogs.com/rickie/archive/2005/04/08/133661.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值