sql broker_使用SQL Server Service Broker进行异步处理

SQL Server Service Broker提供了一种在数据库之间实现异步处理的方式,解决了跨数据库事务的性能和实现问题。通过消息类型、合同、队列和服务等概念,可以创建分布式事务系统。在该文中,介绍了如何利用SQL Service Broker进行消息处理,包括创建消息类型、合同、队列和服务,并展示了如何使用存储过程发送和接收消息,从而实现异步操作。
摘要由CSDN通过智能技术生成

sql broker

介绍 (Introduction)

In the real-world implementation of SQL Server of an enterprise system, it always needs to implement data in multiple databases. In most of the cases, a single transaction will span across multiple databases. If there are multiple databases, there will be performance issues and implementation issues during the cross-database transactions. However, with the use of SQL Service Broker that was introduced in SQL Server 2005, you can implement asynchronous transactions between databases.

在企业系统SQL Server的实际实现中,始终需要在多个数据库中实现数据。 在大多数情况下,单个事务将跨越多个数据库。 如果有多个数据库,则在跨数据库事务期间将存在性能问题和实现问题。 但是,通过使用SQL Server 2005中引入SQL Service Broker,可以在数据库之间实现异步事务。

什么是服务经纪人 (What is Service Broker)

The Service broker is similar to other message queuing technologies such as MSMQ. In the service broker, data can be processed automatically or on-demand. Data in the SQL service broker is consumed by SEND and RECEIVE, which is typically an XML format.

服务代理类似于其他消息排队技术,例如MSMQ。 在服务代理中,可以自动或按需处理数据。 SQL服务代理中的数据由SEND和RECEIVE使用,通常是XML格式。

Service Broker的方案 (A scenario for Service Broker)

Though there are a few other implementations of Service Broker, we will be looking at the usage of Service Broker for the Distributed Transaction System.

尽管还有其他一些Service Broker的实现,但我们将研究Service Broker在分布式事务系统中的用法。

Let us assume that there is an Order System. When the order is received, inventory has to be processed. To maintain scalability and security concerns, these are handled by two processes.

让我们假设有一个订单系统。 收到订单后,必须处理库存。 为了保持可伸缩性和安全性考虑,这些由两个过程处理。

We will start by enabling the service broker from the following code.

我们将从以下代码启用服务代理开始。

ALTER DATABASE OrderDB 
SET ENABLE_BROKER;

In the service broker, we will be using four main concepts: Message Type, Contract, Queue, and Services. The following figure shows different types of objects in Object Explorer for SQL service broker.

在服务代理中,我们将使用四个主要概念:消息类型,合同,队列和服务。 下图显示了用于SQL Service Broker的对象资源管理器中的不同类型的对象。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值