2779B Module 12 - Using Service Broker

 

System Architecture

 

 

Object

Message type: defines valid message

Contract: specifies type of messages and their direction in a conversation

Queue: stores messages before sending and after receipt (inside sql server)

Service: Addressable endpoint for communication

Service Program: Processes messages

 

SQL:

ALTER DATABASE ADVENTUREWORKS SET ENABLE_BROKER;

 

Conversation Architecture

Features

Message: Information exchanged between two services

Dialog conversation: Messages being sent ans received by two services

Conversation Group: A group of related conversations

Route: A network address, and optionally a service name

Remote service binding: dbuser and the remote user

 

Conversation process:

  1. user submits form (xml)
  2. form is received by a stored procedure
  3. message is put in a queue
  4. sent from the queue until the service program at the other end is ready to process the message

 

Security

Transport Security

            -services involved mutually authenticate

Dialog Security

            -full

                        -use PKI messages are encrypted

                        -anon

                                    -access through Guest account

 

Creating message types

-create message type SQL STATEMNT

 

Creating contracts

-Create contract tsql statement

-Initiator is the first service to send a message and remains the initiator.

 

Creating Queues

-Queues are just like sql server tables

-retention: conversations remain until conversation ends.

-activation: queue can activate the service which will send the message.

 

Creating Services

-service is an endpoint

-CREATE SERVICE <name> ON QUEUE

-specify the contract

 

 

Sending Messages

  1. declare a dialog handle variable
  2. begin a dialog conversation
  3. send the message

 

Receiving Messages

  1. Declare variables for storing message details
  2. call the RECEIVE statement
  3. check the message type, and process accordingly
  4. if conversation complete call END CONVERSATION