使用 Azure 入口網站建立服務匯流排主題和主題的訂用帳戶Use the Azure portal to create a Service Bus topic and subscriptions to the topic

在本快速入門中,您會使用 Azure 入口網站來建立服務匯流排主題,然後建立該主題的訂用帳戶。In this quickstart, you use the Azure portal to create a Service Bus topic and then create subscriptions to that topic.

什麼是服務匯流排主題和訂用帳戶?What are Service Bus topics and subscriptions?

服務匯流排主題和訂用帳戶支援「發佈/訂閱」 訊息通訊模型。Service Bus topics and subscriptions support a publish/subscribe messaging communication model. 使用主題和訂用帳戶時,分散式應用程式的元件彼此不直接通訊,相反的,他們會透過扮演中繼角色的主題來交換訊息。When using topics and subscriptions, components of a distributed application do not communicate directly with each other; instead they exchange messages via a topic, which acts as an intermediary.


有別於服務匯流排佇列,服務匯流排佇列中的每個訊息只會由單一取用者處理,主題和訂用帳戶採用發佈/訂閱模式,提供一對多的通訊形式。In contrast with Service Bus queues, in which each message is processed by a single consumer, topics and subscriptions provide a one-to-many form of communication, using a publish/subscribe pattern. 一個主題可以登錄多個訂用帳戶。It is possible to register multiple subscriptions to a topic. 當訊息傳送至主題時,每個訂用帳戶都可取得訊息來個別處理。When a message is sent to a topic, it is then made available to each subscription to handle/process independently. 主題的訂用帳戶類似於虛擬佇列,同樣可接收已傳送到主題的訊息複本。A subscription to a topic resembles a virtual queue that receives copies of the messages that were sent to the topic. 您可以選擇為個別訂用帳戶登錄主題的篩選規則,以篩選或限制主題的哪些訊息由哪些主題訂用帳戶接收。You can optionally register filter rules for a topic on a per-subscription basis, which allows you to filter or restrict which messages to a topic are received by which topic subscriptions.

服務匯流排主題和訂用帳戶可讓您擴大處理非常多使用者和應用程式上大量的訊息。Service Bus topics and subscriptions enable you to scale to process a large number of messages across a large number of users and applications.

在 Azure 入口網站中建立命名空間Create a namespace in the Azure portal

若要開始在 Azure 中使用服務匯流排傳訊實體,您必須先使用 Azure 中的唯一名稱建立命名空間。To begin using Service Bus messaging entities in Azure, you must first create a namespace with a name that is unique across Azure. 命名空間提供範圍容器,可在應用程式內定址服務匯流排資源。A namespace provides a scoping container for addressing Service Bus resources within your application.

若要建立命名空間:To create a namespace:

  1. 登入 Azure 入口網站Sign in to the Azure portal

  2. 在入口網站的左側瀏覽窗格中,依序選取 [+ 建立資源] 、[整合] 及 [服務匯流排] 。In the left navigation pane of the portal, select + Create a resource, select Integration, and then select Service Bus.

    建立資源 -> 整合 -> 服務匯流排

  3. 在 [建立命名空間] 對話方塊中,執行下列步驟:In the Create namespace dialog, do the following steps:

    1. 輸入 命名空間的名稱Enter a name for the namespace. 系統會立即檢查此名稱是否可用。The system immediately checks to see if the name is available. 如需命名空間規則清單,請參閱建立命名空間 REST APIFor a list of rules for naming namespaces, see Create Namespace REST API.

    2. 選取命名空間的定價層 (基本、標準或進階)。Select the pricing tier (Basic, Standard, or Premium) for the namespace. 如果您想要使用主題和訂用帳戶,請選擇 [標準] 或 [進階]。If you want to use topics and subscriptions, choose either Standard or Premium. 基本定價層不支援主題/訂用帳戶。Topics/subscriptions are not supported in the Basic pricing tier.

    3. 如果您選取了 [進階] 定價層,請遵循下列步驟:If you selected the Premium pricing tier, follow these steps:

      1. 指定 傳訊單位 的數目。Specify the number of messaging units. 進階層可讓您的資源在 CPU 和記憶體層級上獲得隔離,讓每個工作負載能夠獨立執行。The premium tier provides resource isolation at the CPU and memory level so that each workload runs in isolation. 此資源容器稱為傳訊單位。This resource container is called a messaging unit. 進階命名空間都至少有一個傳訊單位。A premium namespace has at least one messaging unit. 您可以為每個服務匯流排進階命名空間選取 1、2 或 4 個傳訊單位。You can select 1, 2, or 4 messaging units for each Service Bus Premium namespace. 如需詳細資訊,請參閱服務匯流排進階傳訊For more information, see Service Bus Premium Messaging.
      2. 指定您是否要讓命名空間具有 區域備援功能Specify whether you want to make the namespace zone redundant. 區域備援可免費在單一區域中的可用性區域間散佈複本,而提供更高的可用性。The zone redundancy provides enhanced availability by spreading replicas across availability zones within one region at no additional cost. 如需詳細資訊,請參閱 Azure 中的可用性區域For more information, see Availability zones in Azure.
    4. 針對 [訂用帳戶] ,選擇要在其中建立命名空間的 Azure 訂用帳戶。For Subscription, choose an Azure subscription in which to create the namespace.

    5. 針對 [資源群組] ,選擇將存留命名空間的現有資源群組,或是建立新的資源群組。For Resource group, choose an existing resource group in which the namespace will live, or create a new one.

    6. 針對 [位置] ,選擇應裝載命名空間的區域。For Location, choose the region in which your namespace should be hosted.

    7. 選取 [建立] 。Select Create. 此時系統會建立並啟用命名空間。The system now creates your namespace and enables it. 系統為帳戶提供資源時,您可能需要等幾分鐘。You might have to wait several minutes as the system provisions resources for your account.


  4. 確認服務匯流排命名空間已成功部署。Confirm that the service bus namespace is deployed successfully. 若要查看通知,請選取工具列上的 鈴鐺圖示 (警示)To see the notifications, select the bell icon (Alerts) on the toolbar. 選取通知中的 資源群組名稱,如下圖所示。Select the name of the resource group in the notification as shown in the image. 您會看到包含服務匯流排命名空間的資源群組。You see the resource group that contains the service bus namespace.


  5. 在資源群組的 [資源群組] 頁面上,選取您的 服務匯流排命名空間On the Resource group page for your resource group, select your service bus namespace.

    資源群組頁面 - 選取您的服務匯流排命名空間

  6. 您會看到服務匯流排命名空間的首頁。You see the home page for your service bus namespace.


取得連接字串Get the connection string

建立新命名空間會自動產生初始共用存取簽章 (SAS) 規則,其利用相關聯的主要和次要金鑰組,分別授與命名空間的所有層面的完全控制權。Creating a new namespace automatically generates an initial Shared Access Signature (SAS) rule with an associated pair of primary and secondary keys that each grant full control over all aspects of the namespace. 請參閱服務匯流排驗證與授權,以了解如何建立進一步的規則,對一般傳送者和接收者的權限施加更多限制。See Service Bus authentication and authorization for information about how to create rules with more constrained rights for regular senders and receivers. 若要複製命名空間的主要和次要金鑰,請遵循下列步驟:To copy the primary and secondary keys for your namespace, follow these steps:

  1. 按一下 [所有資源] ,然後按一下新建立的命名空間名稱。Click All resources, then click the newly created namespace name.

  2. 在命名空間視窗中,按一下 [共用存取原則] 。In the namespace window, click Shared access policies.

  3. 在 [共用存取原則] 畫面中,按一下 RootManageSharedAccessKeyIn the Shared access policies screen, click RootManageSharedAccessKey.

    螢幕擷取畫面顯示 [共用存取原則] 視窗,其中已反白顯示原則。

  4. 在 [原則:RootManageSharedAccessKey] 視窗中,按一下 [主要連接字串] 旁邊的 [複製] 按鈕,將連接字串複製到剪貼簿以供後續使用。In the Policy: RootManageSharedAccessKey window, click the copy button next to Primary Connection String, to copy the connection string to your clipboard for later use. 將此值貼到記事本或一些其他暫存位置。Paste this value into Notepad or some other temporary location.

    螢幕擷取畫面顯示名為 RootManageSharedAccessKey 的 S A S 原則,其中包括索引鍵和連接字串。

  5. 重複前一個步驟,複製 [主要金鑰] 的值並貼到暫存位置以供稍後使用。Repeat the previous step, copying and pasting the value of Primary key to a temporary location for later use.

使用 Azure 入口網站建立主題Create a topic using the Azure portal

  1. 在 [服務匯流排命名空間] 頁面上,選取左側功能表上的 [主題]。On the Service Bus Namespace page, select Topics on the left menu.

  2. 選取工具列上的 [+ 主題]。Select + Topic on the toolbar.

  3. 輸入主題的 名稱Enter a name for the topic. 保留其他選項的預設值。Leave the other options with their default values.

  4. 選取 [建立] 。Select Create.


針對主題建立訂用帳戶Create subscriptions to the topic

  1. 選取您在上一節中建立的 主題Select the topic that you created in the previous section.


  2. 在 [服務匯流排主題] 頁面上,從左側功能表中選取 [訂用帳戶],然後選取工具列上的 [+ 訂用帳戶]。On the Service Bus Topic page, select Subscriptions from the left menu, and then select + Subscription on the toolbar.


  3. 在 [建立訂用帳戶] 頁面上,針對訂用帳戶的 名稱 輸入 S1,然後選取 [建立]。On the Create subscription page, enter S1 for name for the subscription, and then select Create.


  4. 重複執行前一個步驟兩次,以建立名為 S2S3 的訂用帳戶。Repeat the previous step twice to create subscriptions named S2 and S3.


您可以使用服務匯流排總管來管理服務匯流排資源。You can manage Service Bus resources with Service Bus Explorer. 服務匯流排總管可讓使用者連線到服務匯流排命名空間,並以簡便的方式管理傳訊實體。The Service Bus Explorer allows users to connect to a Service Bus namespace and administer messaging entities in an easy manner. 此工具提供進階的功能 (例如匯入/匯出功能) 或測試主題、佇列、訂用帳戶、轉送服務、通知中樞和事件中樞的能力。The tool provides advanced features like import/export functionality or the ability to test topic, queues, subscriptions, relay services, notification hubs and events hubs.

後續步驟Next steps

在本文中,您已建立服務匯流排命名空間、命名空間中的主題,以及訂閱該主題的三個訂用帳戶。In this article, you created a Service Bus namespace, a topic in the namespace, and three subscriptions to the topic. 若要了解如何將訊息發佈至主題並訂閱訂用帳戶中的訊息,請參閱「發佈和訂閱訊息」一節中的下列其中一個快速入門。To learn how to publish messages to the topic and subscribe for messages from a subscription, see one of the following quickstarts in the Publish and subscribe for messages section.