You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#customer intent: As a JavaScript developer, I want to learn how to send events to an event hub and receive events from the event hub using C#.
9
9
---
10
10
11
11
# Quickstart: Send events to or receive events from event hubs by using JavaScript
12
-
In this Quickstart, you learn how to send events to and receive events from an event hub using the **@azure/event-hubs** npm package.
13
12
13
+
In this Quickstart, you learn how to send events to and receive events from an event hub using the **@azure/event-hubs** npm package.
14
14
15
15
## Prerequisites
16
+
16
17
If you're new to Azure Event Hubs, see [Event Hubs overview](event-hubs-about.md) before you do this quickstart.
17
18
18
19
To complete this quickstart, you need the following prerequisites:
19
20
20
21
-**Microsoft Azure subscription**. To use Azure services, including Azure Event Hubs, you need a subscription. If you don't have an existing Azure account, you can sign up for a [free trial](https://azure.microsoft.com/free/).
21
22
- Node.js LTS. Download the latest [long-term support (LTS) version](https://nodejs.org).
22
23
- Visual Studio Code (recommended) or any other integrated development environment (IDE).
23
-
-**Create an Event Hubs namespace and an event hub**. The first step is to use the [Azure portal](https://portal.azure.com) to create a namespace of type Event Hubs, and obtain the management credentials your application needs to communicate with the event hub. To create a namespace and an event hub, follow the procedure in [this article](event-hubs-create.md).
24
+
-**Create an Event Hubs namespace and an event hub**. The first step is to use the [Azure portal](https://portal.azure.com) to create a namespace of type Event Hubs, and obtain the management credentials your application needs to communicate with the event hub. For more information, see [Create an event hub using Azure portal](event-hubs-create.md).
24
25
25
26
### Install npm packages to send events
26
-
To install the [Node Package Manager (npm) package for Event Hubs](https://www.npmjs.com/package/@azure/event-hubs), open a command prompt that has *npm* in its path, change the directory
27
-
to the folder where you want to keep your samples.
27
+
28
+
To install the [Node Package Manager (npm) package for Event Hubs](https://www.npmjs.com/package/@azure/event-hubs), open a command prompt that has `npm` in its path, change the directory to the folder where you want to keep your samples.
@@ -138,35 +141,36 @@ In this section, you create a JavaScript application that sends events to an eve
138
141
139
142
---
140
143
141
-
1.Run `node send.js` to execute thisfile. This command sends a batch of three events to your eventhub. If you're using the Passwordless (Azure Active Directory's Role-based Access Control) authentication, you might want to run `az login` and sign into Azure using the account that was added to the Azure Event Hubs Data Owner role.
142
-
1. In the Azure portal, verify that the event hub received the messages. Refreshthe page to update the chart. It might take a few seconds for it to show that the messages are received.
144
+
1.To run this file, enter `node send.js`. This command sends a batch of three events to your eventhub. If you're using the passwordless (Microsoft Entra ID Role-based access control (RBAC)) authentication, you might want to run `az login` and sign into Azure using the account that was added to the Azure Event Hubs Data Owner role.
145
+
1. In the Azure portal, verify that the event hub received the messages. To update the chart, refresh the page. It might take a few seconds for it to show that the messages are received.
143
146
144
-
[](./media/node-get-started-send/verify-messages-portal.png#lightbox)
147
+
:::image type="content" source="./media/node-get-started-send/verify-messages-portal.png" alt-text="Screenshot shows the Overview page where you can verify that the event hub received the message." lightbox="./media/node-get-started-send/verify-messages-portal.png":::
145
148
146
-
> [!NOTE]
147
-
> For the complete source code, including additional informational comments, go to the [GitHub sendEvents.js page](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/eventhub/event-hubs/samples/v5/javascript/sendEvents.js).
148
149
150
+
> [!NOTE]
151
+
> For more information and the complete source code, see [GitHub sendEvents.js page](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/eventhub/event-hubs/samples/v5/javascript/sendEvents.js).
149
152
150
153
## Receive events
154
+
151
155
In this section, you receive events from an event hub by using an Azure Blob storage checkpoint store in a JavaScript application. It performs metadata checkpoints on received messages at regular intervals in an Azure Storage blob. This approach makes it easy to continue receiving messages later from where you left off.
[Get the connection string to the storage account](../storage/common/storage-configure-connection-string.md).
173
+
Get the connection string to the storage account. See [Configure Azure Storage connection strings](../storage/common/storage-configure-connection-string.md).
170
174
171
175
Note the connection string and the container name. You use them in the code to receive events.
> For the complete source code, including additional informational comments, go to the [GitHub receiveEventsUsingCheckpointStore.js page](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/eventhub/eventhubs-checkpointstore-blob/samples/v1/javascript/receiveEventsUsingCheckpointStore.js).
364
+
> For the complete source code, including additional informational comments, see [receiveEventsUsingCheckpointStore.js](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/eventhub/eventhubs-checkpointstore-blob/samples/v1/javascript/receiveEventsUsingCheckpointStore.js).
361
365
362
366
The receiver program receives events from all the partitions of the default consumer group in the event hub.
363
367
364
368
## Clean up resources
369
+
365
370
Delete the resource group that has the Event Hubs namespace or delete only the namespace if you want to keep the resource group.
Copy file name to clipboardExpand all lines: includes/passwordless/event-hub/event-hub-assign-roles.md
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,16 +5,17 @@ services: storage
5
5
author: alexwolfmsft
6
6
ms.service: azure-storage
7
7
ms.topic: include
8
-
ms.date: 09/09/2022
8
+
ms.date: 06/13/2025
9
9
ms.author: alexwolf
10
10
ms.custom: include file
11
11
---
12
12
13
-
When developing locally, make sure that the user account that connects to Azure Event Hubs has the correct permissions. You'll need the [Azure Event Hubs Data Owner](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-owner) role in order to send and receive messages. To assign yourself this role, you'll need the User Access Administrator role, or another role that includes the `Microsoft.Authorization/roleAssignments/write` action. You can assign Azure RBAC roles to a user using the Azure portal, Azure CLI, or Azure PowerShell. Learn more about the available scopes for role assignments on the [scope overview](../../../articles/role-based-access-control/scope-overview.md) page.
13
+
When developing locally, make sure that the user account that connects to Azure Event Hubs has the correct permissions. You need the [Azure Event Hubs Data Owner](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-owner) role in order to send and receive messages. To assign yourself this role, you need the User Access Administrator role, or another role that includes the `Microsoft.Authorization/roleAssignments/write` action. You can assign Azure RBAC roles to a user using the Azure portal, Azure CLI, or Azure PowerShell. For more information about the available scopes for role assignments, see [Understand scope for Azure RBAC](../../../articles/role-based-access-control/scope-overview.md) page.
14
14
15
15
The following example assigns the `Azure Event Hubs Data Owner` role to your user account, which provides full access to Azure Event Hubs resources. In a real scenario, follow the [Principle of Least Privilege](../../../articles/active-directory/develop/secure-least-privileged-access.md) to give users only the minimum permissions needed for a more secure production environment.
16
16
17
17
### Azure built-in roles for Azure Event Hubs
18
+
18
19
For Azure Event Hubs, the management of namespaces and all related resources through the Azure portal and the Azure resource management API is already protected using the Azure RBAC model. Azure provides the below Azure built-in roles for authorizing access to an Event Hubs namespace:
19
20
20
21
-[Azure Event Hubs Data Owner](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-owner): Enables data access to Event Hubs namespace and its entities (queues, topics, subscriptions, and filters)
@@ -24,27 +25,27 @@ For Azure Event Hubs, the management of namespaces and all related resources thr
24
25
If you want to create a custom role, see [Rights required for Event Hubs operations](../../../articles/service-bus-messaging/service-bus-sas.md#rights-required-for-service-bus-operations).
25
26
26
27
> [!IMPORTANT]
27
-
> In most cases, it will take a minute or two for the role assignment to propagate in Azure. In rare cases, it may take up to eight minutes. If you receive authentication errors when you first run your code, wait a few moments and try again.
28
+
> In most cases, it takes a minute or two for the role assignment to propagate in Azure. In rare cases, it might take up to eight minutes. If you receive authentication errors when you first run your code, wait a few moments and try again.
28
29
29
30
### [Azure portal](#tab/roles-azure-portal)
30
31
31
32
1. In the Azure portal, locate your Event Hubs namespace using the main search bar or left navigation.
32
33
33
-
2. On the overview page, select **Access control (IAM)** from the left-hand menu.
34
+
1. On the overview page, select **Access control (IAM)** from the left-hand menu.
34
35
35
-
3. On the **Access control (IAM)** page, select the **Role assignments** tab.
36
+
1. On the **Access control (IAM)** page, select the **Role assignments** tab.
36
37
37
-
4. Select **+ Add** from the top menu and then **Add role assignment** from the resulting drop-down menu.
38
+
1. Select **+ Add** from the top menu and then **Add role assignment** from the resulting drop-down menu.
38
39
39
-
:::image type="content" source="media/event-hub-assign-roles/add-role.png" alt-text="A screenshot showing how to assign a role.":::
40
+
:::image type="content" source="media/event-hub-assign-roles/add-role.png" alt-text="Screenshot showing how to assign a role.":::
40
41
41
-
5. Use the search box to filter the results to the desired role. For this example, search for `Azure Event Hubs Data Owner` and select the matching result. Then choose **Next**.
42
+
1. Use the search box to filter the results to the desired role. For this example, search for `Azure Event Hubs Data Owner` and select the matching result. Then choose **Next**.
42
43
43
-
6. Under **Assign access to**, select **User, group, or service principal**, and then choose **+ Select members**.
44
+
1. Under **Assign access to**, select **User, group, or service principal**, and then choose **+ Select members**.
44
45
45
-
7. In the dialog, search for your Microsoft Entra username (usually your *user@domain* email address) and then choose **Select** at the bottom of the dialog.
46
+
1. In the dialog, search for your Microsoft Entra username (usually your *user@domain* email address) and then choose **Select** at the bottom of the dialog.
46
47
47
-
8. Select **Review + assign** to go to the final page, and then **Review + assign** again to complete the process.
48
+
1. Select **Review + assign** to go to the final page, and then **Review + assign** again to complete the process.
Copy file name to clipboardExpand all lines: includes/passwordless/event-hub/event-hub-passwordless-template-tabbed-basic.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,12 @@ services: storage
5
5
author: diberry
6
6
ms.service: azure-storage
7
7
ms.topic: include
8
-
ms.date: 09/09/2022
8
+
ms.date: 06/13/2025
9
9
ms.author: diberry
10
10
ms.custom: include file
11
11
---
12
12
13
-
This quickstart shows you two ways of connecting to Azure Event Hubs: passwordless and connection string. The first option shows you how to use your security principal in Microsoft Entra ID and role-based access control (RBAC) to connect to an Event Hubs namespace. You don't need to worry about having hard-coded connection strings in your code or in a configuration file or in a secure storage like Azure Key Vault. The second option shows you how to use a connection string to connect to an Event Hubs namespace. If you're new to Azure, you may find the connection string option easier to follow. We recommend using the passwordless option in real-world applications and production environments. For more information, see [Authentication and authorization](../../../articles/service-bus-messaging/service-bus-authentication-and-authorization.md). You can also read more about passwordless authentication on the [overview page](/azure/developer/intro/passwordless-overview).
13
+
This quickstart shows you two ways of connecting to Azure Event Hubs: passwordless and connection string. The first option shows you how to use your security principal in Microsoft Entra ID and role-based access control (RBAC) to connect to an Event Hubs namespace. You don't need to worry about having hard-coded connection strings in your code, in a configuration file, or in secure storage like Azure Key Vault. The second option shows you how to use a connection string to connect to an Event Hubs namespace. If you're new to Azure, you might find the connection string option easier to follow. We recommend using the passwordless option in real-world applications and production environments. For more information, see [Service Bus authentication and authorization](../../../articles/service-bus-messaging/service-bus-authentication-and-authorization.md). For more information, see [Passwordless connections for Azure services](/azure/developer/intro/passwordless-overview).
Creating a new namespace automatically generates an initial Shared Access Signature (SAS) policy with primary and secondary keys and connection strings that each grant full control over all aspects of the namespace. See [Event Hubs authentication and authorization](../../../articles/service-bus-messaging/service-bus-authentication-and-authorization.md) for information about how to create rules with more constrained rights for regular senders and receivers.
29
28
30
29
A client can use the connection string to connect to the Event Hubs namespace. To copy the primary connection string for your namespace, follow these steps:
31
30
32
31
1. On the **Event Hub Namespace** page, select **Shared access policies** on the left menu.
33
-
3. On the **Shared access policies** page, select **RootManageSharedAccessKey**.
34
-
4. In the **Policy: RootManageSharedAccessKey** window, select 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.
32
+
1. On the **Shared access policies** page, select **RootManageSharedAccessKey**.
33
+
1. In the **Policy: RootManageSharedAccessKey** window, select 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.
35
34
36
-
:::image type="content" source="./media/event-hub-passwordless-template-tabbed/connection-string.png"alt-text="Screenshot shows an SAS policy called RootManageSharedAccessKey, which includes keys and connection strings.":::
35
+
:::image type="content" source="./media/event-hub-passwordless-template-tabbed/connection-string.png"alt-text="Screenshot shows an SAS policy called RootManageSharedAccessKey, which includes keys and connection strings.":::
37
36
38
-
You can use this page to copy primary key, secondary key, primary connection string, and secondary connection string.
37
+
You can use this page to copy primary key, secondary key, primary connection string, and secondary connection string.
0 commit comments