Fonctionnalités de Service Broker

Service Broker permet aux développeurs d'élaborer des applications asynchrones, souples d'utilisation, dans lesquelles plusieurs composants indépendants travaillent conjointement pour accomplir une tâche. These application components exchange messages that contain the information that is required to complete the task. This topic describes the following fundamental aspects of Service Broker :

  • Conversations
  • Classement et coordination des messages
  • Programmation asynchrone transactionnelle
  • Prise en charge d'applications faiblement couplées
  • Service Broker components

Conversations

Service Broker is designed around the basic functions of sending and receiving messages. Chaque message représente un élément d'une conversation, autrement dit d'un canal de communication permanent et fiable. Each message and conversation has a specific type that Service Broker enforces to help developers write reliable applications.

New Transact-SQL statements allow applications to reliably send and receive the messages. Une application envoie des messages à un service, désignation sous laquelle est regroupé un ensemble de tâches connexes. Une application reçoit des messages depuis une file d'attente, qui n'est autre qu'une vue de table interne.

Les messages d'une même tâche font partie de la même conversation. Within each conversation, Service Broker guarantees that an application receives each message exactly once, in the order in which the message was sent. The program that implements a service can associate related conversations for the same service in a conversation group, as described in Avantages de Service Broker.

La sécurité basée sur les certificats permet de protéger les messages confidentiels et de contrôler l'accès aux services.

One way to understand Service Broker is to think of it as a postal service. Pour entretenir une conversation avec un collègue éloigné, vous communiquez au moyen de lettres que vous postez. Le service postal responsable du courrier trie les lettres, puis les distribue. Votre collègue et vous-même récupérez ensuite le courrier qui vous est adressé dans vos boîtes aux lettres respectives. Vous lisez votre courrier, y répondez par l'intermédiaire d'une nouvelle lettre envoyée et ce jusqu'à ce que la conversation s'achève. Letter delivery occurs "asynchronously," while you and your colleague handle other tasks.

Deux utilisateurs échangent du courrier à travers un service postal.

Dans l'image du service postal, les messages sont les lettres et A Service Broker service is the address to which the post office delivers the letters. Queues are the mailboxes that hold the letters after they are delivered. Les applications reçoivent les messages, agissent conformément à leur contenu et envoient les réponses.

A program that uses Service Broker holds conversations with other programs in a manner similar to postal delivery.

You do not have to know specifically when your colleague reads mail or writes responses. Similarly, an application that uses Service Broker does not have to know how another service processes a message, how it is delivered, or when the other application processes the message.

Classement et coordination des messages

Service Broker handles queuing, a common database programming technique, differently from traditional products in two key respects:

  • Service Broker queues are integrated into the database.
  • Les files d'attente coordonnent et organisent les messages connexes.

Integrated queuing means that ordinary database maintenance and administration also include Service Broker . Typically an administrator has no routine maintenance tasks related to Service Broker .

The Service Broker framework provides a simple Transact-SQL interface for sending and receiving messages combined with a set of strong guarantees for message delivery and processing. Service Broker guarantees that a program receives each message in a conversation exactly once in the order in which the message was sent, not the order in which the message entered the queue. Traditional queuing products provide messages in the order in which the messages entered the queue, requiring an application to determine the order and grouping of messages. Service Broker guarantees that two queue readers cannot simultaneously process messages from the same conversation or the same group of related conversations.

Le programme initiateur engage une conversation pour chaque tâche, puis envoie un message au service cible. Ce message contient les données indispensables à l'exécution d'une opération spécifique faisant partie d'une tâche. Le service cible reçoit le message. Le programme du service cible traite le message, puis répond au service qui a lancé la conversation. Le dialogue se poursuit et s'achève finalement selon les règles établies par le développeur.

Service Broker handles the most difficult tasks involved in writing messaging applications. These include message coordination, reliable message delivery, locking, and starting queue readers. This lets database developers free to concentrate on solving business problems.

Programmation asynchrone transactionnelle

In the Service Broker infrastructure, message delivery between applications is transactional and asynchronous. Because Service Broker messaging is transactional, if a transaction rolls back, all Service Broker operations in the transaction roll back. This includes send and receive operations. Dans une remise asynchrone, le Moteur de base de données gère la remise des messages tandis que l'application poursuit son exécution. To improve scalability, Service Broker provides mechanisms for automatically starting programs that process a queue when there is useful work for the program to do. For more information, see Service Broker Activation.

La programmation asynchrone constitue une aide pour les développeurs qui écrivent des applications utilisant des files d'attente. Many database applications include tables that function as queues of work to be accomplished as resources allow. Queuing lets the database remain responsive for interactive users while efficiently using available resources. Service Broker provides queuing as an important part the Moteur de base de données.

Queuing lets an application perform work in a different transaction than the transaction that requests the work. Service Broker extends this idea to let applications perform the work in a different instance, or on a different computer. Service Broker helps database developers by providing built-in queuing in the database and reliable, transactional messaging between instances.

Prise en charge d'applications faiblement couplées

Service Broker supports loosely coupled applications. Ces applications sont constituées de plusieurs programmes qui envoient et reçoivent des messages indépendamment les uns des autres. Such applications must contain the same definitions for the exchanged messages and must define the same overall structure for the interaction between the services. However, the applications do not have to run at the same time, run in the same instance of SQL Server, or share implementation details. An application does not have to know the physical location or the implementation of the other participant in the conversation.

Composants de Service Broker

Service Broker has three types of components:

  • Composants de conversation. Conversation groups, conversations, and messages form the run-time structure of a Service Broker application. Les applications échangent des messages dans le cadre d'une conversation. Each conversation is part of one conversation group; a conversation group can contain multiple conversations. Service Broker conversations are dialogs, that is, conversations between exactly two participants. For more information about conversation components, see Architecture des conversations.
  • Composants de définition de service. Il s'agit de composants intervenant au moment de la conception et qui précisent la structure de base de la conversation que l'application utilise. Ils définissent les types de messages, le flux des messages et le stockage de la base de données pour l'application. For more information about service definition components, see Architecture du service.
  • Composants réseau et de sécurité. These components define the infrastructure for exchanging messages outside an instance of SQL Server. To help database administrators manage changing environments, Service Broker lets administrators configure these components independently of the application code. For more information about networking and security components, see Réseau et sécurité distante.

Service definition components, networking components, and security components are part of the metadata for the database and the instance of SQL Server. Les groupes de conversations, les conversations et les messages font partie des données contenues dans la base de données.

Voir aussi

Concepts

Évolutivité de Service Broker

Autres ressources

Architecture de Service Broker
Service Broker Activation
Réflexions diverses sur la sécurité Service Broker
Didacticiels de Service Broker

Aide et Informations

Assistance sur SQL Server 2005