Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Tutorial: Use namespace topics to route MQTT messages to Azure Event Hubs (Azure portal)

Feedback

In this article

In this tutorial, you learn how to use a namespace topic to route data from MQTT clients to Azure Event Hubs.

Prerequisites

  • If you don't have an Azure subscription, create anAzure free account before you begin.
  • If you're new to Event Grid, read theEvent Grid overview before you begin.
  • Register the Event Grid resource provider according to the steps inRegister the Event Grid resource provider.
  • Make sure that port8883 is open in your firewall. The sample in this tutorial uses the MQTT protocol, which communicates over port 8883. This port might be blocked in some corporate and educational network environments.

Create a namespace in the Azure portal

Anamespace in Azure Event Grid is a logical container for one or more topics, clients, client groups, topic spaces, and permission bindings. With an Azure Event Grid namespace, you can group together related resources and manage them as a single unit in your Azure subscription. A unique namespace allows you to have multiple resources in the same Azure region.

To create a namespace:

  1. Sign in to theAzure portal.

  2. In the search box, enterEvent Grid Namespaces and selectEvent Grid Namespaces from the results.

    Screenshot showing Event Grid Namespaces in the search results.

  3. On theEvent Grid Namespaces page, select+ Create.

    Screenshot showing Event Grid Namespaces page with the Create button on the toolbar selected.

  4. On theBasics page, follow these steps.

    1. Select the Azure subscription in which to create the namespace.

    2. Select an existingResource group or create a resource group.

    3. Enter aName for the namespace.

    4. Select theLocation for the namespace.

    5. SelectReview + create.

      Screenshot showing the Basics tab of Create namespace page.

  5. On theReview + create tab, review your settings. Then selectCreate.

  6. On theDeployment succeeded page, selectGo to resource to navigate to your namespace.

Create a namespace topic

  1. If you aren't on the Event Grid Namespace page, follow thecreate, view, and manage namespaces steps to view the namespace you want to use to create the topic.

  2. On theEvent Grid Namespace page, underEvent broker, selectTopics.

  3. On theTopics page, select+ Topic.

    Screenshot showing Event Grid namespace topic creation.

  4. On theCreate Topic page, type the name of the topic you want to create and selectCreate.

    Screenshot showing Event Grid namespace topic creation basics.

Enable managed identity for the Event Grid namespace

  1. On theEvent Grid Namespace page, underSettings, selectIdentity.

  2. To enable a system assigned managed identity, selectOn.

  3. SelectSave to save the setting.

    Screenshot of a system-assigned identity page for an Event Grid namespace.

  4. On the confirmation message, selectYes.

  5. Confirm that you see the object ID of the system-assigned managed identity and see a link to assign roles.

    Screenshot that shows assigning identity to a namespace is completed.

    Check notifications in the Azure portal to confirm that the managed identity is enabled for the namespace.

Enable MQTT broker for the Event Grid namespace

  1. On theEvent Grid Namespace page, underSettings, selectConfiguration.

  2. SelectEnable MQTT broker.

  3. SelectApply.

    Screenshot showing Event Grid namespace configuration page to enable MQTT.

    Check notifications in the Azure portal to confirm that the MQTT broker is enabled for the namespace.

In a separate tab of the Web browser or in a separate window, use the Azure portal to create an Event Hubs namespace with an event hub.

Create an Event Hubs namespace

An Event Hubs namespace provides a unique scoping container in which you create event hubs. To create a namespace in your resource group using the portal:

  1. In the Azure portal, from the flyout menu, selectAll services. In theAll services page, search for and selectEvent Hubs.

    Screenshot showing the selection of Event Hubs in the All services page.

  2. In theEvent Hubs page, selectCreate.

    Screenshot showing the selection of Create button on the Event hubs page.

  3. On theCreate namespace page, take the following steps:

    1. Select theSubscription in which you want to create the namespace.

    2. Select theResource group you created in the previous step.

    3. Enter a name for the namespace. The system immediately checks to see if the name is available.

    4. Select aRegion for the namespace.

    5. For the pricing tier, chooseBasic.

      Note

      If you plan to use the namespace fromApache Kafka apps, use theStandard tier. The basic tier doesn't support Apache Kafka workloads. To learn about differences between tiers, seeQuotas and limits,Event Hubs Premium, andEvent Hubs Dedicated articles.

    6. Leave thethroughput units (for standard tier) orprocessing units (for premium tier) setting as it is. To learn about throughput units or processing units, seeEvent Hubs scalability.

    7. SelectReview + Create.

      Screenshot of the Create Namespace page in the Azure portal.

    8. On theReview + Create page, review the settings, and selectCreate. Wait for the deployment to complete.

  4. On theDeployment page, selectGo to resource to navigate to the page for your namespace.

    Screenshot of the Deployment complete page with the link to resource.

  5. Confirm that you see theEvent Hubs Namespace page similar to the following example:

    Screenshot of the home page for your Event Hubs namespace in the Azure portal.

Create an event hub

To create an event hub within the namespace, do the following actions:

  1. On theOverview page, select+ Event Hub.

    Screenshot of the selection of Add event hub button on the command bar.

  2. Type a name for your event hub, then selectReview + create.

    Screenshot of the Create event hub page.

  3. On theReview + create page, selectCreate.

  4. You can check the status of the event hub creation in alerts. After the event hub is created, you see it in the list of event hubs.

    Screenshot showing the list of event hubs.

Give Event Grid namespace the access to send events to the event hub

  1. On theEvent Hubs Namespace page, selectAccess control (IAM).

  2. On theAccess control page, select+ Add, and then selectAdd role assignment.

    Screenshot that shows the Access control page for the Event Hubs namespace.

  3. On theAdd role assignment page, from the list of roles, selectAzure Event Hubs Data Sender, and then selectNext.

    Screenshot that shows the Add role assignment page with Azure Event Hubs Data Sender selected.

  4. On theMembers page, follow these steps:

    1. For theAssign access to field, selectManaged identity.

    2. Choose+ Select members.

      Screenshot that shows the Add role assignment page with Managed identity selected.

  5. On theSelect managed identities page, follow these steps:

    1. Select your Azure subscription.

    2. ForManaged identity, selectEvent Grid Namespace.

    3. Select the managed identity that has the same name as the Event Grid namespace.

    4. ChooseSelect.

      Screenshot that shows the Select managed identities page with the Event Grid namespace's managed identity selected.

  6. On theAdd role assignment page, selectReview + assign.

  7. On theReview + assign page, selectReview + assign.

Create an event subscription with Event Hubs as the endpoint

  1. Switch to the tab of your Web browser window that has the Event Grid namespace open.

  2. On theEvent Grid Namespace page, selectTopics.

  3. On theTopics page, select the namespace topic you created earlier.

    Screenshot that shows the Topics page with the namespace topic selected.

  4. On theEvent Grid Namespace Topic page, select+ Subscription.

    Screenshot that shows the Subscriptions page.

  5. On theCreate Subscription page, follow these steps:

    1. Enter aName for the event subscription.

    2. ForDelivery mode, selectPush.

    3. Confirm thatEndpoint type is set toEvent Hub.

    4. SelectConfigure an endpoint.

      Screenshot that shows the Create Subscription page.

    5. On theSelect Event Hub page, follow these steps:

      1. Select the Azure subscription that has the event hub.

      2. Select theResource Group that has the event hub.

      3. Select theEvent Hubs Namespace.

      4. Select theEvent Hub in the Event Hubs namespace.

      5. Then, selectConfirm selection.

        Screenshot that shows the Select event hub page.

    6. Back on theCreate Subscription page, selectSystem Assigned forManaged identity type.

    7. SelectCreate.

      Screenshot that shows the Create Subscription page with Create button selected.

Configure routing in the Event Grid namespace

  1. Navigate back to theEvent Grid Namespace page by selecting the namespace in theEssentials section of theEvent Grid Namespace Topic page or by selecting the namespace name in the breadcrumb menu at the top.

  2. On theEvent Grid Namespace page, underMQTT broker, selectRouting.

  3. On theRouting page, selectEnable routing.

  4. ForTopic type, selectNamespace topic.

  5. ForTopic, select the Event Grid namespace topic that you created where all MQTT messages are routed.

  6. SelectApply.

    Screenshot that shows the Routing page with the namespace topic selected.

    Check notifications to confirm that the namespace is enabled with the routing information.

Create clients, topic space, and permission bindings

Follow steps in this quickstart:Publish and subscribe on an MQTT topic to:

  1. Create a client. You can create the second client if you want to, but it's optional.

  2. Create a topic space.

  3. Create publisher and subscriber permission bindings.

  4. Use MQTTX to send a few messages.

  5. Verify that the event hub received those messages on theOverview page for your Event Hubs namespace.

    Screenshot that shows the Overview page of the event hub with incoming message count.

View routed MQTT messages in Event Hubs by using a Stream Analytics query

Navigate to the Event Hubs instance (event hub) in your event subscription in the Azure portal. Process data from your event hub by using Stream Analytics. For more information, seeProcess data from your event hub using Azure Stream Analytics. You can see the MQTT messages in the query.

Screenshot that shows the MQTT messages data in Event Hubs by using the Stream Analytics query tool.

Next step

For code samples, go to theMqttApplicationSamples GitHub repository.


Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?