使用 Service Bus Explorer 在服务总线上运行数据操作

借助 Azure 服务总线,发送方和接收方客户端应用程序可以使用熟悉的点到点(队列)和发布-订阅(主题-订阅)语义来解耦其业务逻辑。

注意

本文重点介绍作为 Azure 门户一部分的 Azure Service Bus Explorer 功能。

社区拥有的开放源代码 Service Bus Explorer 是一个独立的应用程序,并与此应用程序不同。

在 Azure 服务总线命名空间上运行的操作分为两种类型。

  • 管理操作 - 创建、更新和删除服务总线命名空间、队列、主题与订阅。
  • 数据操作 - 向/从队列、主题和订阅发送/接收消息。

重要

  • Service Bus Explorer 不支持管理操作和会话。
  • 我们不建议使用 Service Bus Explorer 处理较大的消息,因为这可能会造成超时(具体取决于消息大小、客户端与服务总线服务之间的网络延迟等)。相反,我们建议使用你自己的客户端来处理较大的消息,因为你可以在其中指定自己的超时值。

先决条件

若要使用 Service Bus Explorer 工具,你需要执行以下任务:

使用 Service Bus Explorer

若要使用 Service Bus Explorer,请导航到要对其执行数据操作的服务总线命名空间。

  1. 如果想要对队列执行操作,请从导航菜单中选择“队列”。 如果想要对主题(及其相关订阅)执行操作,请选择“主题”。

    Screenshot of left side navigation, where entity can be selected.

  2. 选择“队列”或“主题”后,选择特定的队列或主题 。

    Screenshot of the Queues page with a specific queue selected.

  3. 从左侧导航菜单中选择“Service Bus Explorer”

    Screenshot of queue page where Service Bus Explorer can be selected.

    注意

    要从订阅中速览或接收消息时,请先从下拉列表选择器中选择特定的订阅。 Screenshot of dropdown for topic subscriptions.

速览消息

可以使用 Service Bus Explorer 中的速览功能来查看队列、订阅或死信队列中的前 100 条消息。

  1. 若要速览消息,请选择 Service Bus Explorer 下拉列表中的“速览模式”。

    Screenshot of dropdown with Peek Mode selected.

  2. 检查指标以查看是否有要速览的“可用消息”或“死信消息”,然后选择“队列/订阅”或“死信”子队列。

    Screenshot of queue and dead-letter subqueue tabs with message metrics displayed.

  3. 选择“从头开始速览”按钮。

    Screenshot indicating the Peek from start button.

  4. 速览操作完成后,网格中最多会显示 100 条消息,如下图所示。 若要查看特定消息的详细信息,请在网格中选择该消息。 可以选择查看正文或消息属性。

    Screenshot with overview of peeked messages and message body content shown for peeked messages.

    切换到底部窗格中的“消息属性”选项卡以查看元数据

    Screenshot with overview of peeked messages and message properties shown for peeked messages.

    注意

    由于速览不是破坏性操作,因此不会从实体中删除消息。

    注意

    出于性能原因,当从最大消息大小设置为超过 1MB 的队列或订阅中查看消息时,默认情况下不会检索消息正文。 相反,可以通过单击“加载消息正文”按钮来加载特定消息的消息正文。 如果消息正文超过 1MB,它将在显示之前被截断。 Screenshot with overview of peeked messages and button to load message body shown.

使用高级选项速览消息

通过“使用选项速览”功能,可使用 Service Bus Explorer 查看队列、订阅或死信队列中排在前面的消息,指定要速览的消息数以及要从哪一个序列号开始速览。

  1. 若要使用高级选项速览消息,请选择 Service Bus Explorer 下拉列表中的“速览模式”。

    Screenshot of dropdown with Peek Mode selected for peek with advanced options.

  2. 检查指标以查看是否有要速览的“可用消息”或“死信消息”,然后选择“队列/订阅”或“死信”子队列。

    Screenshot of queue and dead-letter subqueue tabs with message metrics displayed for peek with advanced options.

  3. 选择“使用选项速览”按钮。 提供要速览的消息数,以及要从哪一个序列号开始速览,然后选择“速览”按钮。

    Screenshot indicating the Peek with options button, and a page where the options can be set.

  4. 速览操作完成后,网格中显示了消息,如下图所示。 若要查看特定消息的详细信息,请在网格中选择该消息。 可以选择查看正文或消息属性。

    Screenshot with overview of peeked messages and message body content shown for peek with advanced options.

    切换到底部窗格中的“消息属性”选项卡以查看元数据

    Screenshot with overview of peeked messages and message properties shown for peek with advanced options.

    注意

    由于速览不是破坏性操作,因此不会从队列中删除该消息。

接收消息

Service Bus Explorer 上的 receive 函数允许从队列或订阅中接收消息。

  1. 若要接收消息,请在 Service Bus Explorer 下拉列表中选择“接收模式”。

    Screenshot of dropdown with Receive Mode selected.

  2. 检查指标以查看是否有要接收的“可用消息”或“死信消息”,然后选择“队列/订阅”或“死信”。

    Screenshot of queue and dead-letter subqueue tabs with message metrics displayed for receive mode.

  3. 选择“接收消息”按钮,并指定接收模式、要接收的消息数以及接收消息的最长等待时间,然后选择“接收”。

    Screenshot indicating the Receive button, and a page where the options can be set.

    重要

    请注意,ReceiveAndDelete 模式是一种破坏性接收,即当消息显示在 Service Bus Explorer 工具中时,系统会将其从队列中删除。

    若要浏览消息而不将其从队列中删除,请考虑使用“速览”功能,或使用“PeekLock”接收模式。

  4. 接收操作完成后,网格中显示了消息,如下图所示。 若要查看特定消息的详细信息,请在网格中选择该消息。

    Screenshot with overview of received messages and message body content shown.

    Screenshot with overview of received messages and message properties shown.

    注意

    出于性能原因,当从最大消息大小设置为超过 1MB 的队列或订阅接收消息时,一次只会收到一条消息。 如果消息正文超过 1MB,它将在显示之前被截断。

在“PeekLock”模式下接收消息后,可以对该消息执行各种操作。

注意

只能在消息锁定的情况下执行这些操作。

完成消息

  1. 在网格中,选择要完成的已接收消息。

  2. 选择“完成”按钮。

    Screenshot indicating the Complete button.

    重要

    请注意,完成消息是一种破坏性接收,即在 Service Bus Explorer 工具中选择“完成”后,系统将从队列中删除该消息。

延迟消息

  1. 在网格中,选择要延迟的已接收消息。

  2. 选择“延迟”按钮。

    Screenshot indicating the Defer button.

放弃锁定

  1. 在网格中,选择要放弃锁定的已接收消息。

  2. 选择“放弃锁定”按钮。

    Screenshot indicating the Abandon Lock button.

放弃锁定后,该消息可再次用于接收操作。

死信

  1. 在网格中,选择要放入死信队列的已接收消息。

  2. 选择“放入死信队列”按钮。

    Screenshot indicating the Dead-letter button.

将消息放入死信队列后,可从“死信”子队列获取该消息。

向队列或主题发送一条消息

若要向某队列或主题发送消息,请选择 Service Bus Explorer 的“发送消息”按钮。

  1. 选择“Text/Plain”、“Application/Xml”或“Application/Json”作为“内容类型” 。

  2. 对于“消息正文”,请添加消息内容。 确保此内容与前面设置的“内容类型”相匹配。

  3. 设置“代理属性”(可选)- 包括“相关 ID”、“消息 ID”、“ReplyTo”、“标签/主题”、“生存时间 (TTL)”和“计划排队时间”(适用于计划的消息)。

  4. 设置“自定义属性”(可选)- 可以是针对字典键设置的任何用户属性。

  5. 选中“重复发送”以多次发送同一条消息。 如果未设置消息 ID,则会自动使用连续值填充它。

  6. 撰写消息后,选择“发送”按钮。

    Screenshot showing the compose message experience.

  7. 发送操作成功完成后,会发生以下情况之一:

    • 如果是发送到队列,则“可用消息”指标计数器将会递增。
    • 如果是发送到主题,则“可用消息”指标计数器将在消息路由到的订阅上递增。

重新发送消息

在速览或接收消息后,我们可以重新发送它,这会将消息的副本发送到同一实体,同时还可以更新其内容和属性。 即使从死信队列中重新发送,原始内容也会保留且不会删除。

  1. 在网格中,选择要重新发送的消息。

  2. 选择“重新发送所选消息”按钮。

    Screenshot indicating the Resend selected messages button.

  3. 或者,选择任何要更新其详细信息并进行所需更改的消息。

  4. 选择“发送”按钮将消息发送到实体。

    Screenshot showing the resend messages experience.

    注意

    • 重新发送操作会发送原始消息的副本。 它不会删除你重新提交的原始邮件。
    • 如果重新发送订阅的死信队列中的消息,该消息的副本将会发送到主题。 因此,所有订阅都将收到该消息的副本。

切换身份验证类型

使用 Service Bus Explorer 时,可以使用“访问密钥”或“Microsoft Entra ID”身份验证。

  1. 选择“设置”按钮。

    Screenshot indicating the Settings button in Service Bus Explorer.

  2. 选择所需的身份验证方法,然后选择“保存”按钮。

    Screenshot indicating the Settings button and a page showing the different authentication types.

后续步骤