33
DAT340 DAT340 实实实实实实实实 实实实实实实实实 ---SQL Server 2005 Service ---SQL Server 2005 Service Broker Broker

DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

  • View
    298

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

DAT340DAT340    实现异步消息队列实现异步消息队列---SQL Server 2005 Service ---SQL Server 2005 Service BrokerBroker

Page 2: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

异步式编程环境和队列功能 异步式编程环境和队列功能 –– Service BrokerService Broker

回答三个问题:回答三个问题:什么时候需要异步队列操作什么时候需要异步队列操作 ??

Service Broker Service Broker 是什么是什么 ??

为什么要在数据库中处理消息为什么要在数据库中处理消息 ??

具体实现与演示具体实现与演示

Page 3: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

当数据库项目开始的时候当数据库项目开始的时候

VBSQL.OXCVBSQL.OXCVBSQL.OXCVBSQL.OXC

Database ApplicationDatabase Application

ADOADOADOADO

OLEDBOLEDBOLEDBOLEDB

DB-LibraryDB-LibraryDB-LibraryDB-Library

SQLNCLISQLNCLISQLNCLISQLNCLI

Client Network LibraryClient Network LibraryClient Network LibraryClient Network Library

.NET .NET Framework Framework

Data ProviderData Providerfor SQLfor SQLServerServer

.NET .NET Framework Framework

Data ProviderData Providerfor SQLfor SQLServerServer

Storage Storage EngineEngine

Storage Storage EngineEngine

Relational Relational EngineEngine

Relational Relational EngineEngine

TSQL EndpointTSQL EndpointTSQL EndpointTSQL Endpoint

Server Network LibraryServer Network LibraryServer Network LibraryServer Network Library

SQL ServerSQL Server

Architecture of Data Access Architecture of Data Access TechnologiesTechnologies

Page 4: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

重新考虑软件构架中的因素重新考虑软件构架中的因素

性能

吞吐量

容量

功能性

可用性

恢复力

失效安全

容错能力

Have an architecture that makes sense before you write 3.5 millionlines of code.

技术因素

区别 - 没有运动的部分 - 可以创建新材料 - 可以改变物理现象

避免失败 - 将关键部分分散开来 - 语义上的一致性 - 职责分散

Page 5: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

在超市里排队在超市里排队

Page 6: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

在机场里排队在机场里排队

Page 7: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

异步消息队列的使用场景异步消息队列的使用场景

股票交易系统中的结算活动股票交易系统中的结算活动订单输入系统中的发货信息订单输入系统中的发货信息旅行预订系统在客户填写完路线后再进行实际的旅行预订系统在客户填写完路线后再进行实际的预订预订 ,, 并在预订完成后发达确认电子邮件并在预订完成后发达确认电子邮件

Page 8: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

Q2 : Services Broker 是什么?

为什么排队应用程序难以编写?为什么排队应用程序难以编写?

Page 9: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

消息的完整性 消息的完整性 分布分布事务性消息传送事务性消息传送

Page 10: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

The Architecture of SQL Server The Architecture of SQL Server 20052005

SQL Server 2005 Database EngineSQL Server 2005 Database Engine ReplicationReplication

Full-Text Search

Full-Text Search

Service BrokerService Broker

Analysis ServicesAnalysis Services

Integration Services

Integration Services

Reporting Services

Reporting Services

Notification Services

Notification Services

SQL Server Agent

SQL Server Agent

Page 11: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

Service Broker Service Broker 是什么是什么 ??

Platform for building asynchronous queued Platform for building asynchronous queued database applicationsdatabase applications

Queues as first class database objectsQueues as first class database objects

Queue manipulation built into TSQLQueue manipulation built into TSQL

Transactional message processingTransactional message processing

Reliable distributed queuingReliable distributed queuing

Page 12: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

Use Service Broker when you need to:Use Service Broker when you need to:Scale out the system

Improve reliability and availability

Improve application response time

Build an auditing system

Maintain up-to-date cached data

Scale out the system

Improve reliability and availability

Improve application response time

Build an auditing system

Maintain up-to-date cached data

Factors to considerFactors to consider

Large messagesLarge messages

Reliable messagingReliable messaging Heterogeneous dataHeterogeneous data

SecuritySecurity

考虑使用 考虑使用 Service BrokerService Broker 的因素的因素

Page 13: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

Service Broker Service Broker 消息处理事务的步消息处理事务的步骤骤

1. 1. 开始事务。开始事务。2. 2. 从会话组中接收一条或多条消息。从会话组中接收一条或多条消息。3. 3. 从状态表中检索会话的状态。从状态表中检索会话的状态。4. 4. 处理消息并根据消息内容对应用程序数据进行一项或多处理消息并根据消息内容对应用程序数据进行一项或多项更新。项更新。5. 5. 发送一些发送一些 Service Broker Service Broker 消息:即,将响应发送到消息:即,将响应发送到传入的消息或将消息发送到处理传入消息所需的其他服务。传入的消息或将消息发送到处理传入消息所需的其他服务。6. 6. 如果此会话组包含其他消息,则读取和处理此会话组中如果此会话组包含其他消息,则读取和处理此会话组中的其他消息。的其他消息。7. 7. 使用新的会话状态更新会话状态表。使用新的会话状态更新会话状态表。8. 8. 提交事务提交事务

Page 14: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

Q3 :为什么要在数据库中处理消息 ?

Page 15: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

为什么要在数据库中进行消息传送?为什么要在数据库中进行消息传送?消息和数据的单客户端连接。消息和数据的单客户端连接。事务性消息传送不需要分布式事务或两阶段提交。 事务性消息传送不需要分布式事务或两阶段提交。 备份和恢复数据库还可以备份和恢复消息队列。 备份和恢复数据库还可以备份和恢复消息队列。 群集或数据库镜像群集或数据库镜像确定队列中的操作非常简单确定队列中的操作非常简单在提交事务时只需写入单个日志在提交事务时只需写入单个日志可靠的消息传送通常将消息从传送队列传送到接收队列可靠的消息传送通常将消息从传送队列传送到接收队列

Page 16: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

队列读取器管理 队列读取器管理

Page 17: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

ActivationActivation

Page 18: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

具体实现与演示

Page 19: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

Service Broker Service Broker 系统架构系统架构

SQL Server SQL Server ObjectObject DescriptionDescription

Message TypeMessage Type Defines valid messages for exchange between Defines valid messages for exchange between servicesservices

ContractContract Specifies type of messages and their direction in Specifies type of messages and their direction in a conversation, initiator or targeta conversation, initiator or target

QueueQueue Stores messages before sending and after receipt Stores messages before sending and after receipt as result setas result set

Service ProgramService ProgramThe part of a service broker application that The part of a service broker application that reads messages from a queue and processes reads messages from a queue and processes them.them.

ServiceService Addressable endpoint for service communicationAddressable endpoint for service communication

Service programContractServiceService

QueueMessage type

Page 20: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

如何实现 如何实现 Service BrokerService Broker

How to Enable Service Broker in a How to Enable Service Broker in a DatabaseDatabase

Implementing ServicesImplementing Services1.1. How to Create ContractsHow to Create Contracts

2.2. How to Create QueuesHow to Create Queues

3.3. How to Create ServicesHow to Create Services

4.4. How to Send a MessageHow to Send a Message

5.5. How to Receive a MessageHow to Receive a Message

Page 21: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

How to Enable Service Broker in a How to Enable Service Broker in a DatabaseDatabase

Check Service Broker statusCheck Service Broker status11

Enable Service BrokerEnable Service Broker22

SELECT is_broker_enabledFROM sys.databasesWHERE database_id = db_id()

SELECT is_broker_enabledFROM sys.databasesWHERE database_id = db_id()

ALTER DATABASE AdventureWorksSET ENABLE_BROKERALTER DATABASE AdventureWorksSET ENABLE_BROKER

Page 22: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

Implementing ServicesImplementing Services

Design:Design:

Message types

Contracts

Queues

Services

Service program logic

Message types

Contracts

Queues

Services

Service program logic

Page 23: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

1.How to Create Contracts1.How to Create Contracts

Create message typesCreate message types11

Create contractCreate contract22

CREATE CONTRACT CREATE CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense] [//Adventure-Works.com/Expenses/ProcessExpense] ( [//Adventure-Works.com/Expenses/ExpenseClaim] ( [//Adventure-Works.com/Expenses/ExpenseClaim] SENT BY INITIATOR, SENT BY INITIATOR, [// Adventure-Works.com/Expenses/ClaimResponse] [// Adventure-Works.com/Expenses/ClaimResponse] SENT BY TARGET )SENT BY TARGET )

CREATE CONTRACT CREATE CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense] [//Adventure-Works.com/Expenses/ProcessExpense] ( [//Adventure-Works.com/Expenses/ExpenseClaim] ( [//Adventure-Works.com/Expenses/ExpenseClaim] SENT BY INITIATOR, SENT BY INITIATOR, [// Adventure-Works.com/Expenses/ClaimResponse] [// Adventure-Works.com/Expenses/ClaimResponse] SENT BY TARGET )SENT BY TARGET )

CREATE MESSAGE TYPE CREATE MESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim] [//Adventure-Works.com/Expenses/ExpenseClaim] VALIDATION = WELL_FORMED_XML VALIDATION = WELL_FORMED_XML

CREATE MESSAGE TYPE CREATE MESSAGE TYPE [//Adventure-Works.com/Expenses/ClaimResponse] [//Adventure-Works.com/Expenses/ClaimResponse] VALIDATION = VALID_XML WITH SCHEMA COLLECTION awschemasVALIDATION = VALID_XML WITH SCHEMA COLLECTION awschemas

CREATE MESSAGE TYPE CREATE MESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim] [//Adventure-Works.com/Expenses/ExpenseClaim] VALIDATION = WELL_FORMED_XML VALIDATION = WELL_FORMED_XML

CREATE MESSAGE TYPE CREATE MESSAGE TYPE [//Adventure-Works.com/Expenses/ClaimResponse] [//Adventure-Works.com/Expenses/ClaimResponse] VALIDATION = VALID_XML WITH SCHEMA COLLECTION awschemasVALIDATION = VALID_XML WITH SCHEMA COLLECTION awschemas

Page 24: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

2.How to Create Queues2.How to Create Queues

Create queue nameCreate queue name11

Choose whether queue is availableChoose whether queue is available22

Specify any activation parametersSpecify any activation parameters33

CREATE QUEUE ExpenseQueueCREATE QUEUE ExpenseQueue

CREATE QUEUE ExpenseQueueWithActivationCREATE QUEUE ExpenseQueueWithActivationWITH STATUS = OFF, WITH STATUS = OFF, ACTIVATION ( ACTIVATION (

PROCEDURE_NAME = ProcessExpense, PROCEDURE_NAME = ProcessExpense, MAX_QUEUE_READERS = 5, MAX_QUEUE_READERS = 5, EXECUTE AS SELF)EXECUTE AS SELF)

CREATE QUEUE ExpenseQueueCREATE QUEUE ExpenseQueue

CREATE QUEUE ExpenseQueueWithActivationCREATE QUEUE ExpenseQueueWithActivationWITH STATUS = OFF, WITH STATUS = OFF, ACTIVATION ( ACTIVATION (

PROCEDURE_NAME = ProcessExpense, PROCEDURE_NAME = ProcessExpense, MAX_QUEUE_READERS = 5, MAX_QUEUE_READERS = 5, EXECUTE AS SELF)EXECUTE AS SELF)

Page 25: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

Create service nameCreate service name

3.How to Create Services3.How to Create Services

11

Choose storage queueChoose storage queue

List contracts for which the service is a targetList contracts for which the service is a target

Choose whether to retain messages for conversation lifetimeChoose whether to retain messages for conversation lifetime

22

33

44

CREATE SERVICE [//Adventure-Works.com/SubmitExpense] CREATE SERVICE [//Adventure-Works.com/SubmitExpense] ON QUEUE ExpenseQueueON QUEUE ExpenseQueue( [//Adventure-Works.com/Expenses/ProcessExpense] )( [//Adventure-Works.com/Expenses/ProcessExpense] )

CREATE SERVICE [//Adventure-Works.com/SubmitExpense] CREATE SERVICE [//Adventure-Works.com/SubmitExpense] ON QUEUE ExpenseQueueON QUEUE ExpenseQueue( [//Adventure-Works.com/Expenses/ProcessExpense] )( [//Adventure-Works.com/Expenses/ProcessExpense] )

Page 26: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

4.How to Send a Message4.How to Send a Message

Declare a dialog handle variableDeclare a dialog handle variable11

Begin a dialog conversationBegin a dialog conversation22

Send the messageSend the message33

DECLARE @dialog_handle uniqueidentifierDECLARE @dialog_handle uniqueidentifierDECLARE @dialog_handle uniqueidentifierDECLARE @dialog_handle uniqueidentifierDECLARE @dialog_handle uniqueidentifierDECLARE @dialog_handle uniqueidentifier

BEGIN DIALOG CONVERSATION @dialog_handleBEGIN DIALOG CONVERSATION @dialog_handleFROM SERVICE [//Adventure-Works.com/SubmitExpense]FROM SERVICE [//Adventure-Works.com/SubmitExpense]TO SERVICE '//Adventure-Works.com/ProcessExpense'TO SERVICE '//Adventure-Works.com/ProcessExpense'ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense]ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense]

DECLARE @dialog_handle uniqueidentifierDECLARE @dialog_handle uniqueidentifier

BEGIN DIALOG CONVERSATION @dialog_handleBEGIN DIALOG CONVERSATION @dialog_handleFROM SERVICE [//Adventure-Works.com/SubmitExpense]FROM SERVICE [//Adventure-Works.com/SubmitExpense]TO SERVICE '//Adventure-Works.com/ProcessExpense'TO SERVICE '//Adventure-Works.com/ProcessExpense'ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense]ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense]

DECLARE @dialog_handle uniqueidentifierDECLARE @dialog_handle uniqueidentifier

BEGIN DIALOG CONVERSATION @dialog_handleBEGIN DIALOG CONVERSATION @dialog_handleFROM SERVICE [//Adventure-Works.com/SubmitExpense]FROM SERVICE [//Adventure-Works.com/SubmitExpense]TO SERVICE '//Adventure-Works.com/ProcessExpense'TO SERVICE '//Adventure-Works.com/ProcessExpense'ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense]ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense]

SEND ON CONVERSATION @dialog_handleSEND ON CONVERSATION @dialog_handleMESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim]MESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim](@msgString)(@msgString)

DECLARE @dialog_handle uniqueidentifierDECLARE @dialog_handle uniqueidentifier

BEGIN DIALOG CONVERSATION @dialog_handleBEGIN DIALOG CONVERSATION @dialog_handleFROM SERVICE [//Adventure-Works.com/SubmitExpense]FROM SERVICE [//Adventure-Works.com/SubmitExpense]TO SERVICE '//Adventure-Works.com/ProcessExpense'TO SERVICE '//Adventure-Works.com/ProcessExpense'ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense]ON CONTRACT [//Adventure-Works.com/Expenses/ProcessExpense]

SEND ON CONVERSATION @dialog_handleSEND ON CONVERSATION @dialog_handleMESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim]MESSAGE TYPE [//Adventure-Works.com/Expenses/ExpenseClaim](@msgString)(@msgString)

Page 27: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

5.How to Receive a Message5.How to Receive a Message

Declare variables for storing message detailsDeclare variables for storing message details11

Call RECEIVE statementCall RECEIVE statement22

Check the message type, and process accordinglyCheck the message type, and process accordingly33

If finished conversation, call END CONVERSATIONIf finished conversation, call END CONVERSATION44

DECLARE @conversation UNIQUEIDENTIFIERDECLARE @conversation UNIQUEIDENTIFIERDECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @conversation UNIQUEIDENTIFIERDECLARE @conversation UNIQUEIDENTIFIERDECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @conversation UNIQUEIDENTIFIERDECLARE @conversation UNIQUEIDENTIFIERDECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)

;RECEIVE TOP(1) @conversation = conversation_handle,;RECEIVE TOP(1) @conversation = conversation_handle,@msgType = message_type_name, @msg = message_body@msgType = message_type_name, @msg = message_bodyFROM ExpenseQueueFROM ExpenseQueue

DECLARE @conversation UNIQUEIDENTIFIERDECLARE @conversation UNIQUEIDENTIFIERDECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)

;RECEIVE TOP(1) @conversation = conversation_handle,;RECEIVE TOP(1) @conversation = conversation_handle,@msgType = message_type_name, @msg = message_body@msgType = message_type_name, @msg = message_bodyFROM ExpenseQueueFROM ExpenseQueue

DECLARE @conversation UNIQUEIDENTIFIERDECLARE @conversation UNIQUEIDENTIFIERDECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)

;RECEIVE TOP(1) @conversation = conversation_handle,;RECEIVE TOP(1) @conversation = conversation_handle,@msgType = message_type_name, @msg = message_body@msgType = message_type_name, @msg = message_bodyFROM ExpenseQueueFROM ExpenseQueue

IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim')IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim') -- process @msg …-- process @msg …

DECLARE @conversation UNIQUEIDENTIFIERDECLARE @conversation UNIQUEIDENTIFIERDECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)

;RECEIVE TOP(1) @conversation = conversation_handle,;RECEIVE TOP(1) @conversation = conversation_handle,@msgType = message_type_name, @msg = message_body@msgType = message_type_name, @msg = message_bodyFROM ExpenseQueueFROM ExpenseQueue

IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim')IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim') -- process @msg …-- process @msg …

DECLARE @conversation UNIQUEIDENTIFIERDECLARE @conversation UNIQUEIDENTIFIERDECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)

RECEIVE TOP(1) @conversation = conversation_handle,RECEIVE TOP(1) @conversation = conversation_handle,@msgType = message_type_name, @msg = message_body@msgType = message_type_name, @msg = message_bodyFROM ExpenseQueueFROM ExpenseQueue

IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim')IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim') -- process @msg …-- process @msg …END CONVERSATION @conversationEND CONVERSATION @conversation

DECLARE @conversation UNIQUEIDENTIFIERDECLARE @conversation UNIQUEIDENTIFIERDECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)DECLARE @msg NVARCHAR(MAX), @msgType NVARCHAR(256)

RECEIVE TOP(1) @conversation = conversation_handle,RECEIVE TOP(1) @conversation = conversation_handle,@msgType = message_type_name, @msg = message_body@msgType = message_type_name, @msg = message_bodyFROM ExpenseQueueFROM ExpenseQueue

IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim')IF (@msgType = '//Adventure-Works.com/Expenses/ExpenseClaim') -- process @msg …-- process @msg …END CONVERSATION @conversationEND CONVERSATION @conversation

Page 28: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker
Page 29: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

ResourcesResourcesTechnical Chats and Webcastshttp://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/usa/webcasts/default.asp

Microsoft Learning and Certificationhttp://www.microsoft.com/learning/default.mspx

MSDN & TechNet http://microsoft.com/msdnhttp://microsoft.com/technet

Virtual Labshttp://www.microsoft.com/technet/traincert/virtuallab/rms.mspx

Newsgroupshttp://communities2.microsoft.com/communities/newsgroups/en-us/default.aspx

Technical Community Siteshttp://www.microsoft.com/communities/default.mspx

User Groupshttp://www.microsoft.com/communities/usergroups/default.mspx

Page 30: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

ResourcesResources

BlogsBlogshttp://blogs.msdn.com/remusrusanu/http://blogs.msdn.com/remusrusanu/

http://rushi.desai.name/Blog/tabid/54/BlogID/1/Default.aspxhttp://rushi.desai.name/Blog/tabid/54/BlogID/1/Default.aspx

http://blogs.msdn.com/rogerwolterblog/default.aspxhttp://blogs.msdn.com/rogerwolterblog/default.aspx SamplesSamples

http://www.gotdotnet.com/codegallery/codegallery.aspx?http://www.gotdotnet.com/codegallery/codegallery.aspx?id=9f7ae2af-31aa-44dd-9ee8-6b6b6d3d6319id=9f7ae2af-31aa-44dd-9ee8-6b6b6d3d6319

ForumForumhttp://forums.microsoft.com/msdn/ShowForum.aspx?http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=91ForumID=91

Page 31: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

© 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.

MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 32: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

附附 :: 为什么要在数据库中处理消息为什么要在数据库中处理消息 ??

Integrated API for Messages and DataIntegrated API for Messages and DataSingle connection for messaging and other Single connection for messaging and other database operationsdatabase operationsTransactional receives/sends from remote systemsTransactional receives/sends from remote systems

Integrated management, deployment, and Integrated management, deployment, and operationsoperations

Backup, restore, configuration, monitoring, Backup, restore, configuration, monitoring, securitysecurityStartup and shutdown start, recover and stop Startup and shutdown start, recover and stop Service BrokerService BrokerQueued messages and application session state Queued messages and application session state may be queriedmay be queriedTrace Events for monitoring and debuggingTrace Events for monitoring and debuggingMessages have database integrity and Messages have database integrity and recoverabilityrecoverability

Page 33: DAT340 实现异步消息队列 ---SQL Server 2005 Service Broker

附附 :: 为什么要在数据库中处理消息为什么要在数据库中处理消息 ??

Performance advantages for database Performance advantages for database applicationsapplications

No two-phase commits for transactional No two-phase commits for transactional messagingmessagingSingle log write on commitSingle log write on commitNo process boundary crossing to external No process boundary crossing to external messaging softwaremessaging softwareOptimized “in-instance” deliveryOptimized “in-instance” delivery