|
1 | 1 | ---
|
2 |
| -title: Send or receive events from Azure Event Hubs using JavaScript |
| 2 | +title: Send or receive events using JavaScript |
3 | 3 | description: This article provides a walkthrough for creating a JavaScript application that sends/receives events to/from Azure Event Hubs.
|
4 | 4 | ms.topic: quickstart
|
5 |
| -ms.date: 01/04/2023 |
| 5 | +ms.date: 04/05/2024 |
6 | 6 | ms.devlang: javascript
|
7 | 7 | ms.custom: devx-track-js, mode-api, passwordless-js
|
| 8 | +#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#. |
8 | 9 | ---
|
9 | 10 |
|
10 |
| -# Send events to or receive events from event hubs by using JavaScript |
11 |
| -This quickstart shows how to send events to and receive events from an event hub using the **@azure/event-hubs** npm package. |
| 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. |
12 | 13 |
|
13 | 14 |
|
14 | 15 | ## Prerequisites
|
15 | 16 | If you're new to Azure Event Hubs, see [Event Hubs overview](event-hubs-about.md) before you do this quickstart.
|
16 | 17 |
|
17 | 18 | To complete this quickstart, you need the following prerequisites:
|
18 | 19 |
|
19 |
| -- **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/) or use your MSDN subscriber benefits when you [create an account](https://azure.microsoft.com). |
| 20 | +- **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/) or use your MSDN subscriber benefits when you [create an account](https://azure.microsoft.com). |
20 | 21 | - Node.js LTS. Download the latest [long-term support (LTS) version](https://nodejs.org).
|
21 | 22 | - Visual Studio Code (recommended) or any other integrated development environment (IDE).
|
22 | 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).
|
@@ -137,7 +138,7 @@ In this section, you create a JavaScript application that sends events to an eve
|
137 | 138 |
|
138 | 139 | ---
|
139 | 140 |
|
140 |
| -1. Run `node send.js` to execute this file. This command sends a batch of three events to your event hub. |
| 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. |
141 | 142 | 1. In the Azure portal, verify that the event hub has received the messages. Refresh the page to update the chart. It might take a few seconds for it to show that the messages have been received.
|
142 | 143 |
|
143 | 144 | [](./media/node-get-started-send/verify-messages-portal.png#lightbox)
|
@@ -169,7 +170,7 @@ To create an Azure storage account and a blob container in it, do the following
|
169 | 170 |
|
170 | 171 | [Get the connection string to the storage account](../storage/common/storage-configure-connection-string.md).
|
171 | 172 |
|
172 |
| -Note the connection string and the container name. You'll use them in the receive code. |
| 173 | +Note the connection string and the container name. You use them in the receive code. |
173 | 174 |
|
174 | 175 | ---
|
175 | 176 |
|
@@ -350,18 +351,22 @@ npm install @azure/eventhubs-checkpointstore-blob
|
350 | 351 |
|
351 | 352 | 1. Run `node receive.js` in a command prompt to execute this file. The window should display messages about received events.
|
352 | 353 |
|
353 |
| - ``` |
| 354 | + ```bash |
354 | 355 | C:\Self Study\Event Hubs\JavaScript>node receive.js
|
355 | 356 | Received event: 'First event' from partition: '0' and consumer group: '$Default'
|
356 | 357 | Received event: 'Second event' from partition: '0' and consumer group: '$Default'
|
357 | 358 | Received event: 'Third event' from partition: '0' and consumer group: '$Default'
|
358 | 359 | ```
|
| 360 | +
|
359 | 361 | > [!NOTE]
|
360 | 362 | > 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).
|
361 | 363 |
|
362 |
| -You have now received events from your event hub. The receiver program will receive events from all the partitions of the default consumer group in the event hub. |
| 364 | +You have now received events from your event hub. The receiver program receives events from all the partitions of the default consumer group in the event hub. |
| 365 | +
|
| 366 | +## Clean up resources |
| 367 | +Delete the resource group that has the Event Hubs namespace or delete only the namespace if you want to keep the resource group. |
363 | 368 |
|
364 |
| -## Next steps |
| 369 | +## Related content |
365 | 370 | Check out these samples on GitHub:
|
366 | 371 |
|
367 | 372 | - [JavaScript samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/eventhub/event-hubs/samples/v5/javascript)
|
|
0 commit comments