暂停(禁用)和重新激活消息实体Suspend and reactivate messaging entities (disable)

可以暂停队列、主题和订阅。Queues, topics, and subscriptions can be temporarily suspended. 暂停后,实体处于禁用状态,其中所有消息都保留在存储中。Suspension puts the entity into a disabled state in which all messages are maintained in storage. 不过,无法删除或添加消息,相应的协议操作也会导致错误出现。However, messages cannot be removed or added, and the respective protocol operations yield errors.

暂停实体通常是出于紧急管理方面的原因。Suspending an entity is typically done for urgent administrative reasons. 一种情况是,部署的接收程序发生故障,不仅会将消息从队列中剔除、无法处理消息,甚至还会错误地完成并删除消息。One scenario is having deployed a faulty receiver that takes messages off the queue, fails processing, and yet incorrectly completes the messages and removes them. 如果诊断出这样的行为,就会禁用队列的接收行为,直到部署了更正后的代码,并且可以防止故障代码进一步加剧数据丢失问题为止。If that behavior is diagnosed, the queue can be disabled for receives until corrected code is deployed and further data loss caused by the faulty code can be prevented.

暂停或重新激活可以由用户或系统执行。A suspension or reactivation can be performed either by the user or by the system. 系统只会出于重大管理原因(如达到订阅支出限制),才会暂停实体。The system only suspends entities due to grave administrative reasons such as hitting the subscription spending limit. 系统禁用的实体不能被用户重新激活,但在暂停原因消除后就会还原。System-disabled entities cannot be reactivated by the user, but are restored when the cause of the suspension has been addressed.

队列状态Queue status

可以为队列设置如下状态:The states that can be set for a queue are:

  • Active:队列处于活动状态。Active: The queue is active.
  • Disabled:队列处于暂停状态。Disabled: The queue is suspended. 它相当于同时设置 SendDisabled 和 ReceiveDisabled 。It's equivalent to setting both SendDisabled and ReceiveDisabled.
  • SendDisabled:队列部分处于暂停状态,允许执行接收操作。SendDisabled: The queue is partially suspended, with receive being permitted.
  • ReceiveDisabled:队列部分处于暂停状态,允许执行发送操作。ReceiveDisabled: The queue is partially suspended, with send being permitted.

在 Azure 门户中更改队列状态:Change the queue status in the Azure portal:

  1. 在 Azure 门户中,导航到你的服务总线命名空间。In the Azure portal, navigate to your Service Bus namespace.

  2. 选择要更改其状态的队列。Select the queue for which you want to change the status. 可在底部的中间窗格中看到队列。You see queues in the bottom pane in the middle.

  3. 在“服务总线队列”页面上,将看到队列的当前状态显示为超链接。On the Service Bus Queue page, see the current status of the queue as a hyperlink. 如果未在左侧菜单中选择“概述”,请选择该选项以查看队列的状态。If the Overview isn't selected on the left menu, select it to see the status of the queue. 选择队列的当前状态进行更改。Select the current status of the queue to change it.

    选择队列状态

  4. 为队列选择新状态,然后选择“确定”。Select the new status for the queue, and select OK.

    设置队列状态

门户只容许完全禁用队列。The portal only permits completely disabling queues. 也可以单独禁用发送和接收操作,方法是在 .NET Framework SDK 中使用服务总线 NamespaceManager API,或通过 Azure CLI 或 Azure PowerShell 使用 Azure 资源管理器模板。You can also disable the send and receive operations separately using the Service Bus NamespaceManager APIs in the .NET Framework SDK, or with an Azure Resource Manager template through Azure CLI or Azure PowerShell.

使用 Azure PowerShell 更改队列状态Change the queue status using Azure PowerShell

下面的示例展示了用于禁用队列的 PowerShell 命令。The PowerShell command to disable a queue is shown in the following example. 重新激活命令等同于以下示例,只需将 Status 设置为“Active”即可。The reactivation command is equivalent, setting Status to Active.

$q = Get-AzServiceBusQueue -ResourceGroup mygrp -NamespaceName myns -QueueName myqueue

$q.Status = "Disabled"

Set-AzServiceBusQueue -ResourceGroup mygrp -NamespaceName myns -QueueName myqueue -QueueObj $q

后续步骤Next steps

若要了解有关服务总线消息传送的详细信息,请参阅以下主题:To learn more about Service Bus messaging, see the following topics: