19
1 Building Distributed Building Distributed Asynchronous Applications With Asynchronous Applications With SQL Service Broker SQL Service Broker Gerald Hinson, Roger Wolter Gerald Hinson, Roger Wolter DAT303 DAT303 Dev Lead Dev Lead Microsoft Corporation Microsoft Corporation

1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

Embed Size (px)

Citation preview

Page 1: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

1

Building Distributed Asynchronous Building Distributed Asynchronous Applications With SQL Service Applications With SQL Service BrokerBroker

Gerald Hinson, Roger WolterGerald Hinson, Roger WolterDAT303DAT303Dev LeadDev LeadMicrosoft CorporationMicrosoft Corporation

Page 2: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

2

AgendaAgenda

What is Service Broker?What is Service Broker?

Service Broker BasicsService Broker Basics

CLR ServicesCLR Services

Conversation Group LockingConversation Group Locking

WCF ChannelWCF Channel

Remote Service BrokerRemote Service Broker

Page 3: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

3

SQL Service BrokerSQL Service Broker

Platform for building asynchronous,Platform for building asynchronous,loosely coupled database applicationsloosely coupled database applications

Queues are database objectsQueues are database objectsQueue locking reduces conflicts and Queue locking reduces conflicts and deadlocksdeadlocks

Dialogs give unprecedented messageDialogs give unprecedented messageordering assuranceordering assurance

Ordered across transactions, input Ordered across transactions, input applications and output applicationsapplications and output applications

New DDL and DML for messagingNew DDL and DML for messagingUse the same APIs and tools as SQLUse the same APIs and tools as SQL

Reliable messaging for scale outReliable messaging for scale out

Page 4: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

4Database BDatabase BDatabase ADatabase A

DialogsDialogsDialogs provide two-way messaging between two servicesDialogs provide two-way messaging between two services

Dialogs offerDialogs offerGuaranteed deliveryGuaranteed delivery

Exactly-once deliveryExactly-once delivery

In-order deliveryIn-order delivery

Secure communicationsSecure communications

DialogsDialogsMay be long-lived (years) or short-lived (seconds)May be long-lived (years) or short-lived (seconds)

Are lightweightAre lightweight

Are persistent sessionsAre persistent sessions

Customer Customer ServiceService

Travel Travel ServiceService

DialogDialog

Page 5: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

5

ServicesServices

A A ServiceService is a named endpoint that may be is a named endpoint that may be targeted with messagestargeted with messages

Its interface is defined by the messages it Its interface is defined by the messages it consumes and emitsconsumes and emits

Services are scoped by (live in) databases Services are scoped by (live in) databases

It is responsibility of a service’s Service Broker It is responsibility of a service’s Service Broker toto

1) Deliver messages sent from that service to other 1) Deliver messages sent from that service to other servicesservices

2) Store messages that are sent to that service until 2) Store messages that are sent to that service until the service can process themthe service can process them

Every service is mapped to a Every service is mapped to a QueueQueue. Messages sent to a . Messages sent to a service are stored in its associated queueservice are stored in its associated queue

Queues are a new table-like object introduced in SS 2005Queues are a new table-like object introduced in SS 2005

Messages are dequeued using a new verb: RECEIVEMessages are dequeued using a new verb: RECEIVE

Messages may be “peeked” using SELECTMessages may be “peeked” using SELECT

Page 6: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

6

Stored ProcedureStored Procedure

Stored ProcedureStored Procedure

Internal ActivationInternal Activation

QUEUEQUEUE

Page 7: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

7

Service Broker BasicsService Broker Basics

Gerald HinsonGerald HinsonDev LeadDev LeadSQL ServerSQL Server

Page 8: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

8

ServiceService

ServiceService

External ActivationExternal Activation

QueueQueue

ExternalExternal

ActivatorActivator

EventEventQueueQueue

Page 9: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

9

CLR ServicesCLR Services

Gerald HinsonGerald HinsonDev LeadDev LeadSQL ServerSQL Server

Page 10: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

10

Queue ReaderQueue Reader

Queue ReaderQueue Reader

Conversation Group Conversation Group LockingLocking

QUEUEQUEUEDialogDialog

11

DialogDialog22DialogDialog22DialogDialog22

DialogDialog11DialogDialog11

XX

Page 11: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

11

Conversation Group LockingConversation Group Locking

Gerald HinsonGerald HinsonDev LeadDev LeadSQL ServerSQL Server

Page 12: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

12

WCF (“Indigo”) Channel For WCF (“Indigo”) Channel For SSBSSB

Typed ProxyTyped Proxy

SSB ChannelSSB Channel

ClientClient

ADO.NETADO.NET

SQLSQLServerServer

DispatcherDispatcher

SSB ChannelSSB Channel

ADO.NETADO.NET

SQLSQLServerServer

TDTDSS

TDTDSS

Service Service Broker Broker RoutingRouting

ServiceService

Page 13: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

13

WCF ChannelWCF Channel

Gerald HinsonGerald HinsonDev LeadDev LeadSQL ServerSQL Server

Page 14: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

14

CertificateCertificate

Public KeyPublic Key

CertificateCertificate

Public KeyPublic Key

InitiatorInitiator TargetTargetFROMFROM

ServiceService

MessageMessageHeaderHeader

CertificateCertificate

Private KeyPrivate Key

DB DB UserUser

DB DB UserUser

RemotRemoteServiceServic

eeBindingBinding

DB DB UserUser

AuthorizationAuthorization

CertificateCertificate

Private KeyPrivate Key

DB DB UserUser

TO TO

ServicServicee

Dialog SecurityDialog Security

Page 15: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

15

RoutingRoutingSENDSEND

ClassifierClassifiersys.routessys.routes

Page 16: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

16

Remote Service BrokerRemote Service Broker

Gerald HinsonGerald HinsonDev LeadDev LeadSQL ServerSQL Server

Page 17: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

17

Service Broker ScenariosService Broker Scenarios

Asynchronous DB “Stuff”Asynchronous DB “Stuff”Asynchronous Triggers and EventsAsynchronous Triggers and Events

Parallel Stored ProceduresParallel Stored Procedures

Batches and scheduled tasksBatches and scheduled tasks

Data Warehouse populationData Warehouse population

Delayed actions in different transactionsDelayed actions in different transactions

Reliable MessagingReliable MessagingSmart ClientsSmart Clients

Point of SalePoint of Sale

Shop FloorShop Floor

Scaling out asynchronous stuffScaling out asynchronous stuff

Reliable Service Oriented ArchitectureReliable Service Oriented Architecture

Page 18: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

18

ResourcesResources

http://blogs.msdn.com/rushidesai/http://blogs.msdn.com/rushidesai/

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

http://www.sqlservicebroker.com/foruhttp://www.sqlservicebroker.com/forums/ms/

http://msdn.microsoft.com/sql/2005/http://msdn.microsoft.com/sql/2005/

[email protected]@microsoft.com

Page 19: 1 Building Distributed Asynchronous Applications With SQL Service Broker Gerald Hinson, Roger Wolter DAT303 Dev Lead Microsoft Corporation

19

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.