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
# Quickstart: Send events to or receive events from event hubs by using JavaScript
12
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.
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
-
## Prerequisites
16
-
17
-
If you're new to Azure Event Hubs, see [Event Hubs overview](event-hubs-about.md) before you do this quickstart.
15
+
If you're new to Azure Event Hubs, see [Event Hubs overview](event-hubs-about.md) before you begin.
18
16
19
-
To complete this quickstart, you need the following prerequisites:
17
+
## Prerequisites
20
18
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/).
22
-
- Node.js LTS. Download the latest [long-term support (LTS) version](https://nodejs.org).
23
-
- Visual Studio Code (recommended) or any other integrated development environment (IDE).
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).
19
+
- Microsoft Azure subscription. To use Azure services, including Azure Event Hubs, you need a subscription. If you don't have an Azure account, sign up for a [free trial](https://azure.microsoft.com/free/).
20
+
- Node.js LTS. Download the latest [long-term support (LTS) version](https://nodejs.org).
21
+
- Visual Studio Code (recommended) or any other integrated development environment (IDE).
22
+
- Create an Event Hubs namespace and an event hub. Use the [Azure portal](https://portal.azure.com) to create a namespace of type Event Hubs Get the management credentials that your application needs to communicate with the event hub. For more information, see [Create an event hub using Azure portal](event-hubs-create.md).
25
23
26
24
### Install npm packages to send events
27
25
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.
26
+
To install the [Node Package Manager (npm) package for Event Hubs](https://www.npmjs.com/package/@azure/event-hubs), open a Command Prompt window that has `npm` in its path. Change the directory to the folder where you want to keep your samples.
@@ -141,7 +139,16 @@ In this section, you create a JavaScript application that sends events to an eve
141
139
142
140
---
143
141
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.
142
+
1. To run the application, use this command:
143
+
144
+
```bash
145
+
node send.js
146
+
```
147
+
148
+
The command sends a batch of three events to your event hub.
149
+
150
+
If you're using the passwordless (Microsoft Entra ID Role-based access control (RBAC)) authentication, you might need sign into Azure using the account that you added to the Azure Event Hubs Data Owner role. Use the `az login` command.
151
+
145
152
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.
146
153
147
154
:::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":::
@@ -158,7 +165,7 @@ In this section, you receive events from an event hub by using an Azure Blob sto
158
165
159
166
### Create an Azure storage account and a blob container
160
167
161
-
To create an Azure storage account and a blob container in it, do the following actions:
168
+
To create an Azure storage account with a blob container:
162
169
163
170
1. [Create an Azure storage account](../storage/common/storage-account-create.md?tabs=azure-portal)
164
171
1. [Create a blob container in the storage account](../storage/blobs/storage-quickstart-blobs-portal.md#create-a-container)
> 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).
371
+
> For the complete source code, including 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).
365
372
366
373
The receiver program receives events from all the partitions of the default consumer group in the event hub.
367
374
@@ -371,7 +378,5 @@ Delete the resource group that has the Event Hubs namespace or delete only the n
Copy file name to clipboardExpand all lines: articles/event-hubs/includes/storage-checkpoint-store-recommendations.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,15 +9,15 @@ ms.author: spelluru
9
9
ms.custom: "include file"
10
10
---
11
11
12
-
Follow these recommendations when using Azure Blob Storage as a checkpoint store:
12
+
Follow these recommendations when you use Azure Blob Storage as a checkpoint store:
13
13
14
14
- Use a separate container for each consumer group. You can use the same storage account, but use one container per each group.
15
-
- Don't use the container for anything else, and don't use the storage account for anything else.
16
-
- Storage account should be in the same region as the deployed application is located in. If the application is on-premises, try to choose the closest region possible.
15
+
- Don't use the storage account for anything else.
16
+
- Don't use the container for anything else.
17
+
- Create the storage account in the same region as the deployed application. If the application is on-premises, try to choose the closest region possible.
17
18
18
19
On the **Storage account** page in the Azure portal, in the **Blob service** section, ensure that the following settings are disabled.
Copy file name to clipboardExpand all lines: includes/passwordless/event-hub/event-hub-assign-roles.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,15 @@ 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 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.
13
+
When you develop 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 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, 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
+
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 following built-in roles for authorizing access to an Event Hubs namespace:
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)
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).
22
22
-[Azure Event Hubs Data Sender](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-sender): Use this role to give the sender access to Event Hubs namespace and its entities.
23
23
-[Azure Event Hubs Data Receiver](../../../articles/role-based-access-control/built-in-roles.md#azure-event-hubs-data-receiver): Use this role to give the receiver access to Event Hubs namespace and its entities.
24
24
@@ -35,27 +35,27 @@ If you want to create a custom role, see [Rights required for Event Hubs operati
35
35
36
36
1. On the **Access control (IAM)** page, select the **Role assignments** tab.
37
37
38
-
1. 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. Then select**Add role assignment**.
39
39
40
40
:::image type="content" source="media/event-hub-assign-roles/add-role.png" alt-text="Screenshot showing how to assign a role.":::
41
41
42
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**.
43
43
44
-
1. 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**. Then choose **+ Select members**.
45
45
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
+
1. In the dialog, search for your Microsoft Entra username (usually your *user@domain* email address). Choose**Select** at the bottom of the dialog.
47
47
48
-
1. 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. Select**Review + assign** again to complete the process.
49
49
50
50
### [Azure CLI](#tab/roles-azure-cli)
51
51
52
-
To assign a role at the resource level using the Azure CLI, you first must retrieve the resource ID using the `az eventhubs namespace show` command. You can filter the output properties using the `--query` parameter.
52
+
To assign a role at the resource level using the Azure CLI, first get the resource ID using the `az eventhubs namespace show` command. You can filter the output properties using the `--query` parameter.
53
53
54
54
```azurecli
55
-
az eventhubs namespace show -g '<your-event-hub-resource-group>' -n '<your-event-hub-name> --query id
55
+
az eventhubs namespace show -g '<your-event-hub-resource-group>' -n '<your-event-hub-name>' --query id
56
56
```
57
57
58
-
Copy the output `Id` from the preceding command. You can then assign roles using the [az role](/cli/azure/role) command of the Azure CLI.
58
+
Copy the output `Id` from the preceding command. You can then assign roles using the [az role](/cli/azure/role) command.
59
59
60
60
```azurecli
61
61
az role assignment create --assignee "<user@domain>" \
@@ -65,13 +65,13 @@ az role assignment create --assignee "<user@domain>" \
65
65
66
66
### [PowerShell](#tab/roles-powershell)
67
67
68
-
To assign a role at the resource level using Azure PowerShell, you first must retrieve the resource ID using the `Get-AzResource` command.
68
+
To assign a role at the resource level using Azure PowerShell, first get the resource ID using the `Get-AzResource` command.
Copy the `Id` value from the preceding command output. You can then assign roles using the [New-AzRoleAssignment](/powershell/module/az.resources/new-azroleassignment) command in PowerShell.
74
+
Copy the `Id` value from the preceding command output. You can then assign roles using the [New-AzRoleAssignment](/powershell/module/az.resources/new-azroleassignment) command.
Copy file name to clipboardExpand all lines: includes/passwordless/event-hub/event-hub-passwordless-template-tabbed-basic.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,12 @@ 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, 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).
13
+
This quickstart shows you two ways of connecting to Azure Event Hubs:
14
+
15
+
-*Passwordless*. 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.
16
+
-*connection string*. 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.
17
+
18
+
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) and [Passwordless connections for Azure services](/azure/developer/intro/passwordless-overview).
@@ -24,7 +29,7 @@ This quickstart shows you two ways of connecting to Azure Event Hubs: passwordle
24
29
25
30
## Get the connection string
26
31
27
-
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.
32
+
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. For information about how to create rules with more constrained rights for regular senders and receivers, see [Event Hubs authentication and authorization](../../../articles/service-bus-messaging/service-bus-authentication-and-authorization.md).
28
33
29
34
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:
0 commit comments