什么是 Azure 服务总线?What is Azure Service Bus?

Azure 服务总线是一种完全托管的企业集成消息中转站。Azure Service Bus is a fully managed enterprise integration message broker. 服务总线可以分离应用程序和服务。Service Bus can decouple applications and services. 服务总线为异步传输数据和状态提供可靠且安全的平台。Service Bus offers a reliable and secure platform for asynchronous transfer of data and state.

数据通过消息在不同的应用程序和服务之间传输。Data is transferred between different applications and services using messages. 消息采用二进制格式,可能包含 JSON、XML 或纯文本。A message is in binary format and can contain JSON, XML, or just text.

一些常见的消息传送方案包括:Some common messaging scenarios are:

  • 消息Messaging. 传输业务数据,例如销售或采购订单、日志或库存变动。Transfer business data, such as sales or purchase orders, journals, or inventory movements.
  • 分离应用程序Decouple applications. 提高应用程序和服务的可靠性和可伸缩性。Improve reliability and scalability of applications and services. 客户端和服务不必同时处于联机状态。Client and service don't have to be online at the same time.
  • 主题和订阅Topics and subscriptions. 启用发布者和订阅者之间的 1:n 关系。Enable 1:n relationships between publishers and subscribers.
  • 消息会话Message sessions. 实现要求消息排序或消息延迟的工作流。Implement workflows that require message ordering or message deferral.


命名空间是一个适用于所有消息传送组件的容器。A namespace is a container for all messaging components. 多个队列和主题可以位于一个命名空间中,命名空间通常用作应用程序容器。Multiple queues and topics can be in a single namespace, and namespaces often serve as application containers.


消息可以发送到队列,也可以从其接收。Messages are sent to and received from queues. 在能够使用接收应用程序接收并处理消息之前,可以通过队列来存储消息。Queues store messages until the receiving application is available to receive and process them.


队列中的消息会排队,并在到达时加盖时间戳。Messages in queues are ordered and timestamped on arrival. 获得接受后,消息会安全地存储在冗余存储中。Once accepted, the message is held safely in redundant storage. 消息以拉取模式传送,即仅按请求传送消息。Messages are delivered in pull mode, only delivering messages when requested.


也可通过主题发送和接收消息。You can also use topics to send and receive messages. 队列通常用于点到点通信,而主题则用于发布/订阅方案。While a queue is often used for point-to-point communication, topics are useful in publish/subscribe scenarios.


主题可以有多个独立的订阅。Topics can have multiple, independent subscriptions. 主题的订阅者可以收到发送到该主题的每个消息的副本。A subscriber to a topic can receive a copy of each message sent to that topic. 订阅是命名实体。Subscriptions are named entities. 订阅可以保留,但会过期或自动删除。Subscriptions persist, but can expire or autodelete.

你可能不希望单个订阅接收发送给某个主题的所有消息。You may not want individual subscriptions to receive all messages sent to a topic. 如果是这样,则可以使用“规则”和“筛选器”来定义触发可选操作的条件 。If so, you can use rules and filters to define conditions that trigger optional actions. 可以筛选指定的消息并设置或修改消息属性。You can filter specified messages and set or modify message properties. 有关详细信息,请参阅主题筛选器和操作For more information, see Topic filters and actions.

高级功能Advanced features

服务总线包括用于解决更复杂消息传送问题的高级功能。Service Bus includes advanced features that enable you to solve more complex messaging problems. 以下部分说明了这几个功能。The following sections describe several of these features.

消息会话Message sessions

若要在服务总线中创建先进先出 (FIFO) 保证,请使用会话。To create a first-in, first-out (FIFO) guarantee in Service Bus, use sessions. 使用消息会话,可以连贯有序的方式处理一系列无限多的相关消息。Message sessions enable joint and ordered handling of unbounded sequences of related messages. 有关详细信息,请参阅消息会话:先进先出 (FIFO)For more information, see Message sessions: first in, first out (FIFO).


自动转发功能可将队列或订阅链接到另一个队列或主题。The autoforwarding feature chains a queue or subscription to another queue or topic. 它们必须都属于相同的命名空间。They must be part of the same namespace. 使用自动转发,服务总线会自动从队列或订阅中删除消息,并将其放入其他队列或主题中。With autoforwarding, Service Bus automatically removes messages from a queue or subscription and puts them in a different queue or topic. 有关详细信息,请参阅使用自动转发链接服务总线实体For more information, see Chaining Service Bus entities with autoforwarding.

死信队列Dead-letter queue

服务总线支持死信队列 (DLQ)。Service Bus supports a dead-letter queue (DLQ). DLQ 保留无法传递给任何接收方的消息。A DLQ holds messages that can't be delivered to any receiver. 它保留无法处理的消息。It holds messages that can't be processed. 使用服务总线可以从 DLQ 中删除这些消息并对其进行检查。Service Bus lets you remove messages from the DLQ and inspect them. 有关详细信息,请参阅服务总线死信队列概述For more information, see Overview of Service Bus dead-letter queues.

计划的传递Scheduled delivery

可以将消息提交到队列或主题,以便进行延迟处理。You can submit messages to a queue or topic for delayed processing. 可以计划作业,以便在特定时间可供系统处理。You can schedule a job to become available for processing by a system at a certain time. 有关详细信息,请参阅计划的消息For more information, see Scheduled messages.

消息延迟Message deferral

队列或订阅客户端可以延迟一段时间检索消息。A queue or subscription client can defer retrieval of a message until a later time. 此延迟可能是由于应用程序中的特殊情况。This deferral might be because of special circumstances in the application. 该消息将保留在队列或订阅中,但会搁置处理。The message remains in the queue or subscription, but it's set aside. 有关详细信息,请参阅消息延迟For more information, see Message deferral.


客户端批处理允许队列或主题客户端延迟一段时间发送消息。Client-side batching enables a queue or topic client to delay sending a message for a certain period of time. 如果客户端在这段时间内发送其他消息,则会将这些消息以单个批次传送。If the client sends additional messages during this time period, it transmits the messages in a single batch. 有关详细信息,请参阅客户端批处理For more information, see Client-side batching.


一个事务将两个或更多操作组合成执行作用域。A transaction groups two or more operations together into an execution scope. 服务总线支持对单个事务作用域内的消息传送实体执行分组操作。Service Bus supports grouping operations against a single messaging entity within the scope of a single transaction. 消息实体可以是队列、主题或订阅。A message entity can be a queue, topic, or subscription. 有关详细信息,请参阅服务总线事务处理概述For more information, see Overview of Service Bus transaction processing.

筛选和操作Filtering and actions

订阅者可以定义他们希望从主题接收的消息。Subscribers can define which messages they want to receive from a topic. 这些消息采用一个或多个命名订阅规则的形式指定。These messages are specified in the form of one or more named subscription rules. 对于每个匹配规则条件,订阅会生成消息的副本,这对于每个匹配规则可能会以不同方式进行批注。For each matching rule condition, the subscription produces a copy of the message, which can be differently annotated for each matching rule. 有关详细信息,请参阅主题筛选器和操作For more information, see Topic filters and actions.

出现空闲队列时自动删除Autodelete on idle

可以使用“出现空闲队列时自动删除”功能指定一个空闲时间间隔,该时间间隔过后系统会自动删除队列。Autodelete on idle enables you to specify an idle interval after which a queue is automatically deleted. 最短持续时间为 5 分钟。The minimum duration is 5 minutes. 有关详细信息,请参阅 QueueDescription.AutoDeleteOnIdle 属性For more information, see the QueueDescription.AutoDeleteOnIdle Property.

重复检测Duplicate detection

错误可能会导致客户端对发送操作结果产生怀疑。An error could cause the client to have a doubt about the outcome of a send operation. 通过重复检测可以重新发送相同的消息。Duplicate detection enables the sender to resend the same message. 另一种做法是让队列或主题丢弃任何重复副本。Another option is for the queue or topic to discard any duplicate copies. 有关详细信息,请参阅重复检测For more information, see Duplicate detection.

安全协议Security protocols

服务总线支持多种安全协议,例如共享访问签名 (SAS)、Azure 基于角色的访问控制 (Azure RBAC)适用于 Azure 资源的托管标识Service Bus supports security protocols such as Shared Access Signatures (SAS), Azure role-based access control (Azure RBAC) and Managed identities for Azure resources.

异地灾难恢复Geo-disaster recovery

在 Azure 区域数据中心遭遇停机的情况下,可以使用异地灾难恢复在其他区域或数据中心进行数据处理,以实现连续运行。When Azure regions or datacenters experience downtime, Geo-disaster recovery enables data processing to continue operating in a different region or datacenter. 有关详细信息,请参阅 Azure 服务总线异地灾难恢复For more information, see Azure Service Bus Geo-disaster recovery.


服务总线支持标准的 AMQP 1.0HTTP/REST 协议。Service Bus supports standard AMQP 1.0 and HTTP/REST protocols.

客户端库Client libraries

服务总线支持用于 .NETJavaJMS 的客户端库。Service Bus supports client libraries for .NET, Java, and JMS.


服务总线与以下 Azure 服务完全集成:Service Bus fully integrates with the following Azure services:

后续步骤Next steps

有关服务总线消息传送入门的内容,请参阅以下文章:To get started using Service Bus messaging, see the following articles: