1. Trang chủ
  2. » Công Nghệ Thông Tin

Instructor Inputs - Session 16 ppt

14 147 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 14
Dung lượng 772,57 KB

Nội dung

1.0 Querying and Managing Data Using SQL Server 2005 In this session, you will learn to: Appreciate message-based communication Implement Service Broker Objectives Begin the session by s

Trang 1

Instructor Inputs S e

Trang 3

This session includes Chapter 11 of the Student Guide

Slide 1

Slide 1 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

In this session, you will learn to:

Appreciate message-based communication Implement Service Broker

Objectives

Begin the session by sharing the objectives with the students

In this session, the students will learn about the benefits of message-based

communication Further, they will learn how to implement message-based communication

using the Service Broker feature of SQL Server 2005

Session Overview

Trang 4

Slide 2 of 14 Session 16

Ver 1.0

Flash presentation: Implementing Service Broker

Introduction to Service Broker

Use the given flash presentation to introduce message-based communication Service Broker to the students

Inputs for the Flash Presentation

When showing the presentation you can use the following inputs to explain the concepts: Screen 1

This screen shows an analogy of a message-based communication In a cargo service a service sends messages to another service A service is represented by a user and a message is represented as a cargo parcel A user sends a cargo parcel to the cargo office near his location The cargo parcel processes the request to deliver the message to the other user The first user can continue his work as he is assured that the message will be delivered An acknowledgement can also be sent to the user telling that the request is processed

Screen 2

The screen displays the communication architecture

Mention that the Service Broker feature of SQL Server 2005 helps in implementing message-based communication It shows how a message is sent and processed The architecture shows various components that are included in communication These

Trang 5

components include message type, contract, service program, service, and a queue

Explain the importance of each component using the following points:

„ Message type: Specifies the type of messages that will be sent

„ Contract: Defines the agreement between two services This agreement specifies

that two services will communicate with each other It also specifies the type of

messages that will be sent or received

„ Service program: Processes a request sent as a message

„ Queue: Stores messages When Service Broker receives a message for a service,

Service Broker inserts the message into the queue for that service

„ Service: Participates in a communication Each service is associated with one queue

When a message arrives for a service, Service Broker places the message in the

queue associated with that service

You can further explain that Microsoft SQL Server 2005 integrates Service Broker with

the database engine It helps the database developer to build reliable, scalable, and secure

database With Service Broker integrated with database engine, database developers can

now add the features like asynchronous communication and reliable-query processing to

the database

Slide 3

Slide 3 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

Is explained by the following diagram.

Introduction to Service Broker Conversation Process

Using this slide you can reiterate the communication process

Trang 6

Slide 4 of 14 Session 16

Ver 1.0

Just a minute

Which of the following objects processes a message from a queue?

1 Service

2 Service program

3 Contract

Answer:

2 Service program

Reiterate the concept taught by asking the given question

In the following topics, you will teach how to implement Service Broker in SQL Server This involves creating different objects that are used to send or receive messages

Slide 5

Slide 5 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

Message:

Is an entity that is exchanged between the Service Broker services

Can contain a validation over the datatype that a message possesses

Is of a specific message type

Message Type:

Can be created by using the CREATE MESSAGE TYPE command

Syntax:

CREATE MESSAGE TYPE message_type_name [ VALIDATION = { NONE | EMPTY | WELL_FORMED_XML | VALID_XML WITH SCHEMA COLLECTION schema_collection_name } ] [ ; ]

Let’s see how…

Creating Messages

Trang 7

In this topic, you need to explain messages to the students In addition, you also need to

explain how to create a message You can tell that a message the data that is

communicated between two ends A message is of a particular message type, if specified

Otherwise, the message type is of the DEFAULT message type You can create a message

type using the CREATE MESSAGE TYPE command Explain the syntax of the

command

Slide 6

Slide 6 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

Queue:

Is an object that stores the messages Can be viewed like a pipeline for messages

Is created by using the CREATE QUEUE command Syntax:

CREATE QUEUE <object> [ WITH [ STATUS = { ON

| OFF } [ , ] ] [ RETENTION = { ON | OFF } [ , ] ] [ ACTIVATION ( [ STATUS = { ON | OFF } , ] PROCEDURE_NAME = <procedure> ,

MAX_QUEUE_READERS = max_readers , EXECUTE AS { SELF | 'user_name' | OWNER } ) ] ]

Let’s see how…

Creating Queues

In this topic, you need to explain queues to the students Tell the students that a queue is

represented as a table and a message acts as a row in the queue

The row contains the content of the message as well as information about the message

type, the service targeted by the message, the contract that the message follows, the

validation performed on the message, the conversation that the message is a part of, and

information internal to the queue An application uses the information in the message row

to identify each message uniquely and process the message appropriately

Applications receive messages from the queue for the service For each conversation,

queues return messages in the order in which the sender sent the message All the

messages returned from a single receive operation are part of conversations that belong to

one conversation group Queues do not return messages in strict first-in-first-out order

Instead, they return messages for each conversation in the order in which the messages

were sent

Trang 8

Slide 7 of 14 Session 16

Ver 1.0

Contract:

Is an agreement between two services that need to communicate with each other

Specifies the type of message that will be used in a conversation

Is created by using the CREATE CONTRACT command Syntax:

CREATE CONTRACT contract_name [ AUTHORIZATION owner_name ] ( { { message_type_name | [ DEFAULT ] } SENT BY { INITIATOR | TARGET | ANY } } [ , n] ) [ ; ]

Let’s see how…

Creating Contracts

In this topic, you need to explain what a contract is and how to implement it You can tell that a contract specifies which message types can be used to accomplish the desired work The contract also specifies which participant in the conversation can use each message type Some message types can be sent by either participant; other message types are restricted to be sent only by the initiator or only by the target

Service Broker also includes a built-in contract named DEFAULT The DEFAULT contract contains only the message type SENT BY ANY If no contract is specified in the BEGIN DIALOG statement, Service Broker uses the DEFAULT contract

Explain the syntax of the CREATE CONTRACT command

Trang 9

Slide 8

Slide 8 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

Service:

Is used by the Service Broker to deliver messages to the correct queue within a database

Is used to route messages, to enforce the contract for a conversation, and to determine the remote security for a new conversation

Is created by using the CREATE SERVICE command Syntax:

CREATE SERVICE service_name [ AUTHORIZATION owner_name ] ON QUEUE

[ schema_name ]queue_name [ ( contract_name | [DEFAULT] [ , n ] ) ] [ ; ]

Let’s see how…

Creating Services

In this topic, you need to explain what a service is and how it is implemented in SQL

Server

A service is an end point of conversation A conversation in Service Broker can contain

two types of services: target and initiating A target service represents an address that

accepts requests for the tasks identified by the contracts that the service specifies An

initiating service represents a return address for a conversation with a target service

Each service uses a queue to store messages Messages sent to the service are delivered to

the queue To create a service, you need to do the following tasks:

1 Create message types that define the data that can be sent back and forth

2 Create a contract that identifies the message types that can be used, and which

endpoint can send them, in order to accomplish a particular task

3 Create an application to receive, process, and send messages as necessary to

accomplish the given task

4 Create a queue to store the incoming messages for the service You may associate the

queue with an activation stored procedure so that the broker automatically activates

the stored procedure to process messages as messages arrive

5 Create a service and associate it with the queue that will receive the messages for the

service

Trang 10

Slide 9 of 14 Session 16

Ver 1.0

Services communicate through a dialog.

Conversation can begin using the BEGIN DIALOG command.

Syntax:

BEGIN DIALOG [ CONVERSATION ]

@dialog_handle FROM SERVICE initiator_service_name

TO SERVICE 'target_service_name']

[ ON CONTRACT contract_name ]

Let’s see how…

Beginning a Conversation

In this topic, you need to explain how to begin a conversation process using the BEGIN DIALOG command In addition you can tell that communication between two

applications occurs through messages As an application sends messages, Service Broker handles the details of locating a route for the service and transmitting the message to the target service

Service Broker communicates the status of a conversation to an application through messages Service Broker indicates errors or the end of a conversation status

Trang 11

Slide 10

Slide 10 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

command.

Syntax:

SEND ON CONVERSATION conversation_handle [ MESSAGE TYPE message_type_name ] [ ( message_body_expression ) ] [ ; ]

Let’s see how…

Sending and Receiving Messages

In this topic, you will explain how messages are sent using the SEND ON

CONVERSATION command Explain the syntax of the command

Slide 11

Slide 11 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

Problem Statement:

The management of AdventureWorks, Inc wants to know the exact yearly sales at any point of the year to help them plan future strategies The aggregated yearly sales data is maintained

in the SalesDetails table of the SalesDB database.

The sales transaction details are stored in the SalesOrderHeader and SalesOrderDetails tables in the AdventureWorks database

To keep the yearly sales data updated, you need to ensure that whenever any order is processed and its shipping date is updated in the AdventureWorks database, the total monetary value of that order, stored in the SubTotal column of the table, should be added to the total yearly sales in the SalesDB database

Demo: Implementing Service Broker

Trang 12

Datafiles_for_faculty\QMDS2005\Chapter 11\Activity folder in the TIRM CD

When demonstrating this activity, you can use the Demo1.txt file provided in the

Datafiles_for_faculty\QMDS2005\Chapter 11\Activity folder in the TIRM CD This file contains all the commands that you need to type for various tasks involved in the

solution You can directly copy the commands from this file and execute them in the

Query Pane.

Slide 12

Slide 12 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

Solution:

To solve the preceding problem, you need to perform the following tasks:

1 Create a service program.

2 Create message types, contract, queues, and service objects.

3 Create a trigger on the SalesOrderHeader table.

4 Verify the functionality.

Demo: Implementing Service Broker

You can also check that the transaction is committed even if the database is not available

by detaching the database Next, you can execute the INSERT statement in the

Sales.SalesOrderHeader table in the AdventureWorks database The record will be inserted in the table even if the SalesDB database is not available Finally, you can again attach the SalesDB database After attaching the database, you will notice that the sales amount will be added to the total yearly sales amount

Trang 13

Slide 13

Slide 13 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

In this session, you learned that:

Service Broker provides a platform that allows the developers

to create asynchronous and reliable query processing.

In Service Broker, the developers create services that converse with each other by sending and receiving messages.

A message is data exchanged between services.

Each message is of a specific message type.

A service is a database object that provides an endpoint for a conversation.

A contract is an agreement between the services that participate in a conversation.

Each service is associated with a queue that acts as a container that stores messages.

A service program provides the required service to which a message is forwarded by the queue for processing.

Summary

Summarize the session

Slide 14

Slide 14 of 14 Session 16

Ver 1.0

Querying and Managing Data Using SQL Server 2005

When implementing Service Broker, you need to create message, queue, contract, service, and conversation database objects.

A message can be created by using the CREATE MESSAGE TYPE command.

A queue can be created by using the CREATE QUEUE command.

A contract can be created by using the CREATE CONTRACT command.

A service can be created by using the CREATE SERVICE command.

A conversation can be started by using the BEGIN DIALOG command.

Messages can be sent by using the SEND ON CONVERSATION command.

Summary (Contd.)

Ngày đăng: 31/07/2014, 15:20

TỪ KHÓA LIÊN QUAN

w