快速入门:使用 Azure 门户创建队列并添加消息Quickstart: Create a queue and add a message with the Azure portal

本快速入门介绍如何使用 Azure 门户在 Azure 存储中创建队列、添加消息和取消消息的排队。In this quickstart, you learn how to use the Azure portal to create a queue in Azure Storage, and to add and dequeue messages.

先决条件Prerequisites

若要访问 Azure 存储,需要一个 Azure 订阅。To access Azure Storage, you'll need an Azure subscription. 如果还没有订阅,请在开始前创建一个 1 元试用帐户If you don't already have a subscription, create a 1rmb trial account before you begin.

对 Azure 存储进行的所有访问都要通过存储帐户完成。All access to Azure Storage takes place through a storage account. 对于本快速入门,请使用 Azure 门户、Azure PowerShell 或 Azure CLI 创建存储帐户。For this quickstart, create a storage account using the Azure portal, Azure PowerShell, or Azure CLI. 有关如何创建存储帐户的帮助,请参阅创建存储帐户For help creating a storage account, see Create a storage account.

创建队列Create a queue

若要在 Azure 门户中创建队列,请执行以下步骤:To create a queue in the Azure portal, follow these steps:

  1. 导航到 Azure 门户中的新存储帐户。Navigate to your new storage account in the Azure portal.

  2. 在存储帐户的左侧菜单中滚动到“队列服务”部分,然后选择“队列”。 In the left menu for the storage account, scroll to the Queue service section, then select Queues.

  3. 选择“+ 队列”按钮。 Select the + Queue button.

  4. 键入新队列的名称。Type a name for your new queue. 队列名称必须小写,必须以字母或数字开头,并且只能包含字母、数字和短划线 (-) 字符。The queue name must be lowercase, must start with a letter or number, and can include only letters, numbers, and the dash (-) character.

  5. 选择“确定”以创建队列。 Select OK to create the queue.

    显示如何在 Azure 门户中创建队列的屏幕截图

添加消息Add a message

接下来,将消息添加到新队列。Next, add a message to the new queue. 消息的大小最大可为 64 KB。A message can be up to 64 KB in size.

  1. 从存储帐户中的队列列表内选择新队列。Select the new queue from the list of queues in the storage account.

  2. 选择“+ 添加消息”按钮以将消息添加到队列。 Select the + Add message button to add a message to the queue. 在“消息文本”字段中输入消息。 Enter a message in the Message text field.

  3. 指定消息何时过期。Specify when the message expires. 验证“到期时间”字段中输入的值是否介于 1 秒到 7 天之间。Valid values that can be entered in the Expires in field are between 1 second and 7 days. 选择“消息永不过期”表示消息将一直保留在队列中,直到显式删除。Select Message never expires to indicate a message that will remain in the queue until it is explicitly removed.

  4. 指示是否要将消息编码为 Base64。Indicate whether to encode the message as Base64. 建议对二进制数据编码。Encoding binary data is recommended.

  5. 选择“确定”按钮添加该消息。****Select the OK button to add the message.

    显示如何将消息添加到队列的屏幕截图

查看消息属性View message properties

添加消息后,Azure 门户会显示队列中所有消息的列表。After you add a message, the Azure portal displays a list of all of the messages in the queue. 可以查看消息 ID、消息内容、消息插入时间和消息过期时间。You can view the message ID, the contents of the message, the message insertion time, and the message expiration time. 此外,可以查看此消息的取消排队次数。You can also see how many times this message has been dequeued.

显示消息属性的屏幕截图

将消息移出队列Dequeue a message

可以在 Azure 门户中,将队列前部的消息取消排队。You can dequeue a message from the front of the queue from the Azure portal. 将消息取消排队时,会删除该消息。When you dequeue a message, the message is deleted.

取消排队始终会删除队列中最早的消息。Dequeueing always removes the oldest message in the queue.

显示如何在门户中取消消息排队的屏幕截图

后续步骤Next steps

本快速入门介绍了如何在 Azure 门户中创建队列、添加消息、查看消息属性和取消消息排队。In this quickstart, you learned how to create a queue, add a message, view message properties, and dequeue a message in the Azure portal.