Azure 服务总线 - 常见问题解答 (FAQ)Azure Service Bus - Frequently asked questions (FAQ)

本文讨论了一些关于 Azure 服务总线的常见问题解答。This article discusses some frequently asked questions about Azure Service Bus. 还可以访问 Azure 支持常见问题解答了解常规的 Azure 定价和支持信息。You can also visit the Azure Support FAQs for general Azure pricing and support information.


本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

关于 Azure 服务总线的一般问题General questions about Azure Service Bus

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

Azure 服务总线 是一个异步消息传送云平台,可让你在分离的系统之间发送数据。Azure Service Bus is an asynchronous messaging cloud platform that enables you to send data between decoupled systems. Azure 以服务的形式提供此功能,这意味着不需要托管自有硬件就能使用它。Azure offers this feature as a service, which means that you don't need to host your own hardware to use it.

什么是服务总线命名空间?What is a Service Bus namespace?

命名空间提供了用于对应用程序中的服务总线资源进行寻址的范围容器。A namespace provides a scoping container for addressing Service Bus resources within your application. 必须创建命名空间才能使用服务总线,而且这也是开始使用的第一步。Creating a namespace is necessary to use Service Bus and is one of the first steps in getting started.

什么是 Azure 服务总线队列?What is an Azure Service Bus queue?

服务总线队列是用于存储消息的实体。A Service Bus queue is an entity in which messages are stored. 有多个应用程序,或者有多个需要彼此通信的分布式应用程序部分时,队列特别有用。Queues are useful when you have multiple applications, or multiple parts of a distributed application that need to communicate with each other. 队列和发行中心的相似之处在于,两者都会接收多个产品(消息),再从该处送出。The queue is similar to a distribution center in that multiple products (messages) are received and then sent from that location.

什么是 Azure 服务总线主题和订阅?What are Azure Service Bus topics and subscriptions?

主题可被视为队列,使用多个订阅时,它成为更丰富的消息传送模型;实质上是一种一对多的通信工具。A topic can be visualized as a queue and when using multiple subscriptions, it becomes a richer messaging model; essentially a one-to-many communication tool. 此发布/订阅模型(或 pub/sub)启用了一个应用程序,该应用程序将消息发送到具有多个订阅的主题中,进而使多个应用程序接收到该消息。This publish/subscribe model (or pub/sub) enables an application that sends a message to a topic with multiple subscriptions to have that message received by multiple applications.

什么是分区实体?What is a partitioned entity?

传统的队列或主题由单个消息中转站进行处理并存储在一个消息存储中。A conventional queue or topic is handled by a single message broker and stored in one messaging store. 仅在基本和标准消息传递层中受支持,分区队列或主题由多个消息中转站处理,并存储在多个消息传送存储中。Supported only in the Basic and Standard messaging tiers, a partitioned queue, or topic is handled by multiple message brokers and stored in multiple messaging stores. 此功能意味着分区的队列或主题的总吞吐量不再受到单个消息中转站或消息存储的性能限制。This feature means that the overall throughput of a partitioned queue or topic is no longer limited by the performance of a single message broker or messaging store. 此外,消息传送存储的临时中断不会导致分区队列或主题不可用。Also, a temporary outage of a messaging store doesn't render a partitioned queue or topic unavailable.

使用分区实体时不保证排序。Ordering isn't ensured when using partitioned entities. 如果某个分区不可用,仍可从其他分区发送和接收消息。In the event that a partition is unavailable, you can still send and receive messages from the other partitions.

高级 SKU 中不再支持分区实体。Partitioned entities are no longer supported in the Premium SKU.

我需要在防火墙上打开哪些端口?What ports do I need to open on the firewall?

可以将以下协议与 Azure 服务总线配合使用,以便发送和接收消息:You can use the following protocols with Azure Service Bus to send and receive messages:

  • 高级消息队列协议 (AMQP)Advanced Message Queuing Protocol (AMQP)
  • 服务总线消息传送协议 (SBMP)Service Bus Messaging Protocol (SBMP)

请查看下表,了解需要打开哪些出站端口,以便使用这些协议与 Azure 事件中心通信。See the following table for the outbound ports you need to open to use these protocols to communicate with Azure Event Hubs.

协议Protocol 端口Ports 详细信息Details
AMQPAMQP 5671 和 56725671 and 5672 请参阅 AMQP 协议指南See AMQP protocol guide
SBMPSBMP 9350 到 93549350 to 9354 请参阅连接模式See Connectivity mode

需要将哪些 IP 地址添加到允许列表?What IP addresses do I need to add to allow list?

若要查找要添加到允许列表以进行连接的正确 IP 地址,请执行以下步骤:To find the right IP addresses to add to allow list for your connections, follow these steps:

  1. 从命令提示符处运行以下命令:Run the following command from a command prompt:

    nslookup <YourNamespaceName>
  2. 记下在 Non-authoritative answer 中返回的 IP 地址。Note down the IP address returned in Non-authoritative answer. 此 IP 地址是静态的。This IP address is static. 只有在你将命名空间还原到另一群集时,它才会更改。The only time it would change is if you restore the namespace on to a different cluster.

如果对命名空间使用区域冗余,则需执行一些额外的步骤:If you use the zone redundancy for your namespace, you need to do a few additional steps:

  1. 首先,在命名空间中运行 nslookup。First, you run nslookup on the namespace.

    nslookup <yournamespace>
  2. 记下“非权威回答”部分中的名称,该名称采用下述格式之一:Note down the name in the non-authoritative answer section, which is in one of the following formats:

  3. 为每一个运行 nslookup,使用后缀 s1、s2 和 s3 获取所有三个在三个可用性区域中运行的实例的 IP 地址。Run nslookup for each one with suffixes s1, s2, and s3 to get the IP addresses of all three instances running in three availability zones,

我可以在哪里找到客户端向命名空间发送/从中接收消息的 IP 地址?Where can I find the IP address of the client sending/receiving messages to/from a namespace?

我们不记录客户端向命名空间发送或从中接收消息的 IP 地址。We don't log the IP addresses of clients sending or receiving messages to/from your namespace. 重新生成密钥,以便所有现有的客户端将无法进行身份验证并查看基于角色的访问控制 (RBAC) 设置,以确保仅允许的用户或应用程序可以访问该命名空间。Regenerate keys so that all existing clients will fail to authenticate and review role-based access control (RBAC) settings to ensure that only allowed users or applications have access to the namespace.

如果使用的是高级命名空间,请使用 IP 筛选虚拟网络服务终结点专用终结点来限制对命名空间的访问。If you're using a premium namespace, use IP filtering, virtual network service endpoints, and private endpoints to limit access to the namespace.

最佳实践Best practices

Azure 服务总线的最佳实践有哪些?What are some Azure Service Bus best practices?

请参阅使用服务总线改进性能的最佳做法 - 此文介绍了如何在交换消息时优化性能。See Best practices for performance improvements using Service Bus - this article describes how to optimize performance when exchanging messages.

创建实体前的须知事项有哪些?What should I know before creating entities?

队列和主题的以下属性是固定不变的。The following properties of a queue and topic are immutable. 预配实体时,请考虑此限制,因为只有创建新的替代实体才可修改这些属性。Consider this limitation when you provision your entities, as these properties can't be modified without creating a new replacement entity.

  • 分区Partitioning
  • 会话Sessions
  • 重复检测Duplicate detection
  • 快速实体Express entity


本部分回答了一些关于服务总线定价结构的常见问题解答。This section answers some frequently asked questions about the Service Bus pricing structure.

服务总线定价和计费译文介绍了服务总线中的计费标准。The Service Bus pricing and billing article explains the billing meters in Service Bus. 有关服务总线定价选项的具体信息,请参阅服务总线定价详细信息For specific information about Service Bus pricing options, see Service Bus pricing details.

还可以访问 Azure 支持常见问题解答了解常规的 Azure 定价信息。You can also visit the Azure Support FAQs for general Azure pricing information.

服务总线如何收取费用?How do you charge for Service Bus?

有关服务总线定价的完整信息,请参阅服务总线定价For complete information about Service Bus pricing, see Service Bus pricing details. 除标示的价格外,还需为在其中部署应用程序的数据中心之外的相关数据输出支付费用。In addition to the prices noted, you are charged for associated data transfers for egress outside of the data center in which your application is provisioned.

服务总线的哪些使用情况受数据传输限制?What usage of Service Bus is subject to data transfer? 哪些不受限制?What isn't?

在给定 Azure 区域内的任何数据传输和入站数据传输均不收费。Any data transfer within a given Azure region is provided at no charge, as well as any inbound data transfer. 区域外的数据传输需收取输出费用,详见此处Data transfer outside a region is subject to egress charges, which can be found here.

服务总线是否对存储收费?Does Service Bus charge for storage?

不能。No. 服务总线不对存储收费。Service Bus doesn't charge for storage. 但是,对每个队列/主题可以保留的数据最大量设有配额限制。However, there's a quota limiting the maximum amount of data that can be persisted per queue/topic. 请参阅下一个常见问题。See the next FAQ.

我有一个服务总线标准命名空间。I have a Service Bus Standard namespace. 为什么我在资源组 '$system' 下看到收费信息?Why do I see charges under resource group '$system'?

Azure 服务总线最近升级了计费组件。Azure Service Bus recently upgraded the billing components. 由于此更改,如果你有服务总线标准命名空间,则可能会在资源组 '$system' 下看到资源 '/subscriptions/<azure_subscription_id>/resourceGroups/$system/providers/Microsoft.ServiceBus/namespaces/$system' 的行项目。Because of this change, if you have a Service Bus Standard namespace, you may see line items for the resource '/subscriptions/<azure_subscription_id>/resourceGroups/$system/providers/Microsoft.ServiceBus/namespaces/$system' under resource group '$system'.

这些费用表示已预配服务总线标准命名空间的每个 Azure 订阅的基本费用。These charges represent the base charge per Azure subscription that has provisioned a Service Bus Standard namespace.

请务必注意,这些费用不是新的,即它们也存在于以前的计费模型中。It's important to note that these charges aren't new, that is, they existed in the previous billing model too. 唯一的更改是它们现在列在 '$system' 下。The only change is that they're now listed under '$system'. 这是由于新的计费系统中的限制所致,新的计费系统将订阅级别的费用分组,而不是绑定到 '$system' 资源 ID 下的特定资源。It's done because of constraints in the new billing system that groups subscription level charges, not tied to a specific resource, under the '$system' resource ID.


有关服务总线限制和配额的列表,请参阅服务总线配额概述For a list of Service Bus limits and quotas, see the Service Bus quotas overview.

如何处理大小 > 1 MB 的消息?How to handle messages of size > 1 MB?

服务总线消息服务(队列和主题/订阅)允许应用程序发送大小不超过 256 KB(标准层)或 1 MB(高级层)的消息。Service Bus messaging services (queues and topics/subscriptions) allow application to send messages of size up to 256 KB (standard tier) or 1 MB (premium tier). 若要处理大小超过 1 MB 的消息,请使用此博客文章中所述的声明检查模式。If you're dealing with messages of size greater than 1 MB, use the claim check pattern described in this blog post.


为什么在从其他订阅中删除命名空间后无法创建该命名空间?Why am I not able to create a namespace after deleting it from another subscription?

从订阅中删除命名空间时,请等待 4 个小时,然后才能在另一个订阅中使用相同的名称重新创建它。When you delete a namespace from a subscription, wait for 4 hours before recreating it with the same name in another subscription. 否则,可能会收到以下错误消息:Namespace already existsOtherwise, you may receive the following error message: Namespace already exists.

Azure 服务总线 API 生成了哪些异常?建议采取什么操作?What are some of the exceptions generated by Azure Service Bus APIs and their suggested actions?

有关可能的服务总线异常的列表,请参阅异常概述For a list of possible Service Bus exceptions, see Exceptions overview.

什么是共享访问签名?哪些语言支持生成签名?What is a Shared Access Signature and which languages support generating a signature?

共享访问签名是基于 SHA-256 安全哈希或 URI 的身份验证机制。Shared Access Signatures are an authentication mechanism based on SHA-256 secure hashes or URIs. 有关如何在 Node.js、PHP、Java、Python 和 C# 中生成自己的签名的信息,请参阅共享访问签名一文。For information about how to generate your own signatures in Node.js, PHP, Java, Python, and C#, see the Shared Access Signatures article.

订阅和命名空间管理Subscription and namespace management

如何将命名空间迁移到另一个 Azure 订阅中?How do I migrate a namespace to another Azure subscription?

可以使用 Azure 门户或 PowerShell 命令,将命名空间从一个 Azure 订阅移到另一个 Azure 订阅。You can move a namespace from one Azure subscription to another, using either the Azure portal or PowerShell commands. 若要执行此操作,命名空间必须已处于活动状态。To execute the operation, the namespace must already be active. 执行这些命令的用户必须是源订阅和目标订阅的管理员。The user executing the commands must be an administrator on both the source and target subscriptions.


若要使用 Azure 门户将服务总线命名空间迁移到其他订阅,可按照此处的说明操作。To use the Azure portal to migrate Service Bus namespaces to another subscription, follow the directions here.


下面的 PowerShell 命令序列将命名空间从一个 Azure 订阅迁移到另一个 Azure 订阅。The following sequence of PowerShell commands moves a namespace from one Azure subscription to another. 若要执行此操作,命名空间必须已经处于活动状态,而且运行 PowerShell 命令的用户必须同时是源订阅和目标订阅的管理员。To execute this operation, the namespace must already be active, and the user running the PowerShell commands must be an administrator on both the source and target subscriptions.

# Create a new resource group in target subscription
Select-AzSubscription -SubscriptionId 'ffffffff-ffff-ffff-ffff-ffffffffffff'
New-AzResourceGroup -Name 'targetRG' -Location 'China East'

# Move namespace from source subscription to target subscription
Select-AzSubscription -SubscriptionId 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
$res = Find-AzResource -ResourceNameContains mynamespace -ResourceType 'Microsoft.ServiceBus/namespaces'
Move-AzResource -DestinationResourceGroupName 'targetRG' -DestinationSubscriptionId 'ffffffff-ffff-ffff-ffff-ffffffffffff' -ResourceId $res.ResourceId

后续步骤Next steps

若要了解有关服务总线的详细信息,请参阅以下文章:To learn more about Service Bus, see the following articles: