暂停(禁用)和重新激活消息实体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.

出于紧急管理原因,你可能希望暂停实体。You may want to suspend an entity for urgent administrative reasons. 例如,有故障的接收程序将消息从队列中移出、无法处理消息,还会错误地完成消息并将其删除。For example, a faulty receiver takes messages off the queue, fails processing, and yet incorrectly completes the messages and removes them. 在这种情况下,建议禁用接收队列,直到更正和部署代码为止。In this case, you may want to disable the queue for receives until you correct and deploy the code.

暂停或重新激活可以由用户或系统执行。A suspension or reactivation can be performed either by the user or by the system. 系统只会出于重大管理原因(如达到订阅支出限制),才会暂停实体。The system only suspends entities because of 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. 可以向队列发送消息或从队列接收消息。You can send messages to and receive messages from the queue.
  • Disabled:队列处于暂停状态。Disabled: The queue is suspended. 它相当于同时设置 SendDisabled 和 ReceiveDisabled 。It's equivalent to setting both SendDisabled and ReceiveDisabled.
  • SendDisabled:不能将消息发送到队列,但可以从队列接收消息。SendDisabled: You can't send messages to the queue, but you can receive messages from it. 如果尝试将消息发送到队列,则会出现异常。You'll get an exception if you try to send messages to the queue.
  • ReceiveDisabled:可以将消息发送到队列,但不能从队列接收消息。ReceiveDisabled: You can send messages to the queue, but you can't receive messages from it. 如果尝试接收队列的消息,则会出现异常。You'll get an exception if you try to receive messages to the queue.

在 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.

    设置队列状态

也可以禁用发送和接收操作,方法是在 .NET SDK 中使用服务总线 NamespaceManager API,或通过 Azure CLI 或 Azure PowerShell 使用 Azure 资源管理器模板。You can also disable the send and receive operations using the Service Bus NamespaceManager APIs in the .NET SDK, or using 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

主题状态Topic status

可以在 Azure 门户中更改主题状态。You can change topic status in the Azure portal. 选择主题的当前状态以查看下一页,这将允许更改状态。Select the current status of the topic to see the following page, which allows you to change the status.

更改主题状态

可以为主题设置如下状态:The states that can be set for a topic are:

  • 活动:主题处于活动状态。Active: The topic is active. 可以将消息发送到主题。You can send messages to the topic.
  • Disabled:主题已暂停。Disabled: The topic is suspended. 不能将消息发送到主题。You can't send messages to the topic.
  • SendDisabled:状态与“禁用”效果相同。SendDisabled: Same effect as Disabled. 不能将消息发送到主题。You can't send messages to the topic. 如果尝试将消息发送到主题,则会出现异常。You'll get an exception if you try to send messages to the topic.

订阅状态Subscription status

可以在 Azure 门户中更改订阅状态。You can change subscription status in the Azure portal. 选择订阅的当前状态以查看下一页,这将允许更改状态。Select the current status of the subscription to see the following page, which allows you to change the status.

更改订阅状态

可以为订阅设置如下状态:The states that can be set for a subscription are:

  • 活动:订阅处于活动状态。Active: The subscription is active. 可以从订阅接收消息。You can receive messages frm the subscription.
  • Disabled:订阅已暂停。Disabled: The subscription is suspended. 不能从订阅接收消息。You can't receive messages from the subscription.
  • ReceiveDisabled:状态与“禁用”效果相同。ReceiveDisabled: Same effect as Disabled. 不能从订阅接收消息。You can't receive messages from the subscription. 如果尝试接收订阅的消息,则会出现异常。You'll get an exception if you try to receive messages to the subscription.
主题状态Topic status 订阅状态Subscription status 行为Behavior
可用Active 可用Active 可以将消息发送到主题,并从订阅接收消息。You can send messages to the topic and receive messages from the subscription.
可用Active “禁用”或“接收已禁用”Disabled or Receive Disabled 可以将消息发送到主题,但不能从订阅接收消息You can send messages to the topic, but you can't receive messages from the subscription
“禁用”或“发送已禁用”Disabled or Send Disabled 可用Active 不能将消息发送到主题,但可以接收已在订阅中的消息。You can't send messages to the topic, but you can receive messages that are already at the subscription.
“禁用”或“发送已禁用”Disabled or Send Disabled “禁用”或“接收已禁用”Disabled or Receive Disabled 无法将消息发送到主题,也无法从订阅接收消息。You can't send messages to the topic and you can't receive from the subscription either.

其他状态Other statuses

EntityStatus 枚举还定义了一组只能由系统设置的过渡状态。The EntityStatus enumeration also defines a set of transitional states that can only be set by the system.

后续步骤Next steps

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