Skip to content

Commit fd710f2

Browse files
Freshness, in progress.
1 parent c6a5722 commit fd710f2

File tree

9 files changed

+63
-57
lines changed

9 files changed

+63
-57
lines changed

articles/event-hubs/event-hubs-node-get-started-send.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
---
2-
title: Send or receive events using JavaScript
3-
description: This article provides a walkthrough for creating a JavaScript application that sends/receives events to/from Azure Event Hubs.
2+
title: 'Quickstart: Send or receive events using JavaScript'
3+
description: This article provides a walkthrough for creating JavaScript applications that send or receive events to and from Azure Event Hubs.
44
ms.topic: quickstart
5-
ms.date: 04/05/2024
5+
ms.date: 06/13/2025
66
ms.devlang: javascript
77
ms.custom: devx-track-js, mode-api, passwordless-js
88
#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#.
99
---
1010

1111
# 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.
1312

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.
1414

1515
## Prerequisites
16+
1617
If you're new to Azure Event Hubs, see [Event Hubs overview](event-hubs-about.md) before you do this quickstart.
1718

1819
To complete this quickstart, you need the following prerequisites:
1920

2021
- **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/).
2122
- Node.js LTS. Download the latest [long-term support (LTS) version](https://nodejs.org).
2223
- 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).
2425

2526
### 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.
2829

2930
### [Passwordless (Recommended)](#tab/passwordless)
3031

@@ -59,8 +60,9 @@ In this section, you create a JavaScript application that sends events to an eve
5960
## [Passwordless (Recommended)](#tab/passwordless)
6061

6162
In the code, use real values to replace the following placeholders:
62-
* `EVENT HUBS NAMESPACE NAME`
63-
* `EVENT HUB NAME`
63+
64+
- `EVENT HUBS NAMESPACE NAME`
65+
- `EVENT HUB NAME`
6466

6567
```javascript
6668
const { EventHubProducerClient } = require("@azure/event-hubs");
@@ -102,8 +104,9 @@ In this section, you create a JavaScript application that sends events to an eve
102104
## [Connection String](#tab/connection-string)
103105

104106
In the code, use real values to replace the following placeholders:
105-
* `EVENT HUB NAME`
106-
* `EVENT HUBS NAMESPACE CONNECTION STRING`
107+
108+
- `EVENT HUB NAME`
109+
- `EVENT HUBS NAMESPACE CONNECTION STRING`
107110

108111
```javascript
109112
const { EventHubProducerClient } = require("@azure/event-hubs");
@@ -138,35 +141,36 @@ In this section, you create a JavaScript application that sends events to an eve
138141

139142
---
140143

141-
1. Run `node send.js` to execute this file. This command sends a batch of three events to your event hub. 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. Refresh the 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 event hub. 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.
143146
144-
[![Verify that the event hub received the messages](./media/node-get-started-send/verify-messages-portal.png)](./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":::
145148
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).
148149
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).
149152
150153
## Receive events
154+
151155
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.
152156
153157
[!INCLUDE [storage-checkpoint-store-recommendations](./includes/storage-checkpoint-store-recommendations.md)]
154158
155-
156159
### Create an Azure storage account and a blob container
160+
157161
To create an Azure storage account and a blob container in it, do the following actions:
158162
159163
1. [Create an Azure storage account](../storage/common/storage-account-create.md?tabs=azure-portal)
160-
2. [Create a blob container in the storage account](../storage/blobs/storage-quickstart-blobs-portal.md#create-a-container)
161-
3. Authenticate to the blob container
164+
1. [Create a blob container in the storage account](../storage/blobs/storage-quickstart-blobs-portal.md#create-a-container)
165+
1. Authenticate to the blob container
162166
163167
## [Passwordless (Recommended)](#tab/passwordless)
164168
165169
[!INCLUDE [event-hub-storage-assign-roles](../../includes/passwordless/event-hub/event-hub-storage-assign-roles.md)]
166170
167171
## [Connection String](#tab/connection-string)
168172
169-
[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).
170174
171175
Note the connection string and the container name. You use them in the code to receive events.
172176
@@ -205,6 +209,7 @@ npm install @azure/eventhubs-checkpointstore-blob
205209
### [Passwordless (Recommended)](#tab/passwordless)
206210

207211
In the code, use real values to replace the following placeholders:
212+
208213
- `EVENT HUBS NAMESPACE NAME`
209214
- `EVENT HUB NAME`
210215
- `STORAGE ACCOUNT NAME`
@@ -281,8 +286,8 @@ npm install @azure/eventhubs-checkpointstore-blob
281286
282287
### [Connection String](#tab/connection-string)
283288
284-
285289
In the code, use real values to replace the following placeholders:
290+
286291
- `EVENT HUBS NAMESPACE CONNECTION STRING`
287292
- `EVENT HUB NAME`
288293
- `STORAGE CONNECTION STRING`
@@ -346,8 +351,7 @@ npm install @azure/eventhubs-checkpointstore-blob
346351
347352
---
348353
349-
350-
1. Run `node receive.js` in a command prompt to execute this file. The window should display messages about received events.
354+
1. To run this file, enter `node receive.js`. The window should display messages about received events.
351355
352356
```bash
353357
C:\Self Study\Event Hubs\JavaScript>node receive.js
@@ -357,14 +361,16 @@ npm install @azure/eventhubs-checkpointstore-blob
357361
```
358362
359363
> [!NOTE]
360-
> 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).
361365
362366
The receiver program receives events from all the partitions of the default consumer group in the event hub.
363367
364368
## Clean up resources
369+
365370
Delete the resource group that has the Event Hubs namespace or delete only the namespace if you want to keep the resource group.
366371
367372
## Related content
373+
368374
Check out these samples on GitHub:
369375
370376
- [JavaScript samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/eventhub/event-hubs/samples/v5/javascript)

articles/event-hubs/includes/storage-checkpoint-store-recommendations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Provides recommendations when using Azure Blob Storage as a checkpo
44
author: spelluru
55
ms.service: azure-event-hubs
66
ms.topic: include
7-
ms.date: 02/15/2024
7+
ms.date: 06/13/2025
88
ms.author: spelluru
99
ms.custom: "include file"
1010
---
10.1 KB
Loading
-41.6 KB
Loading

includes/passwordless/event-hub/event-hub-assign-roles.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ services: storage
55
author: alexwolfmsft
66
ms.service: azure-storage
77
ms.topic: include
8-
ms.date: 09/09/2022
8+
ms.date: 06/13/2025
99
ms.author: alexwolf
1010
ms.custom: include file
1111
---
1212

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.
1414

1515
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.
1616

1717
### Azure built-in roles for Azure Event Hubs
18+
1819
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:
1920

2021
- [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
2425
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).
2526

2627
> [!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.
2829
2930
### [Azure portal](#tab/roles-azure-portal)
3031

3132
1. In the Azure portal, locate your Event Hubs namespace using the main search bar or left navigation.
3233

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.
3435

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.
3637

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.
3839

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.":::
4041

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**.
4243

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**.
4445

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.
4647

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.
4849

4950
### [Azure CLI](#tab/roles-azure-cli)
5051

includes/passwordless/event-hub/event-hub-passwordless-template-tabbed-basic.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ services: storage
55
author: diberry
66
ms.service: azure-storage
77
ms.topic: include
8-
ms.date: 09/09/2022
8+
ms.date: 06/13/2025
99
ms.author: diberry
1010
ms.custom: include file
1111
---
1212

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).
1414

1515
## [Passwordless (Recommended)](#tab/passwordless)
1616

@@ -20,21 +20,20 @@ This quickstart shows you two ways of connecting to Azure Event Hubs: passwordle
2020

2121
[!INCLUDE [event-hub-assign-roles](event-hub-assign-roles.md)]
2222

23-
24-
2523
## [Connection String](#tab/connection-string)
2624

2725
## Get the connection string
26+
2827
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.
2928

3029
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:
3130

3231
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.
3534

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.":::
3736

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.
3938

4039
---

0 commit comments

Comments
 (0)