-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[event-hubs] migrate samples to v2 (#15053)
Followed the steps at https://github.com/Azure/azure-sdk-for-js/wiki/Samples-v2-Migration-Guide /cc @willmtemple Note: I moved browserSamples and expressSamples into the generated v5 samples folder since dev-tool doesn't work with those.
- Loading branch information
Showing
58 changed files
with
1,713 additions
and
479 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 5 additions & 15 deletions
20
...s/samples/typescript/src/receiveEvents.ts → ...b/event-hubs/samples-dev/receiveEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
...hubs/samples/typescript/src/sendEvents.ts → ...thub/event-hubs/samples-dev/sendEvents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...s/samples/typescript/src/useWithIotHub.ts → ...b/event-hubs/samples-dev/useWithIotHub.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT Licence. | ||
|
||
/** | ||
* @summary Demonstrates how to instantiate EventHubsClient using AAD token credentials obtained from using service principal secrets. | ||
* | ||
* @azsdk-weight 40 | ||
*/ | ||
|
||
/* | ||
* Setup : | ||
* Register a new application in AAD and assign the "Azure Event Hubs Data Owner" role to it | ||
* - See https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app | ||
* to register a new application in the Azure Active Directory. | ||
* - Note down the CLIENT_ID and TENANT_ID from the above step. | ||
* - In the "Certificates & Secrets" tab, create a secret and note that down. | ||
* - In the Azure portal, go to your Even Hubs resource and click on the Access control (IAM) | ||
* tab. Here, assign the "Azure Event Hubs Data Owner" role to the registered application. | ||
* - For more information on Event Hubs RBAC setup, learn more at https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-role-based-access-control) | ||
* | ||
*/ | ||
|
||
import { EventHubConsumerClient } from "@azure/event-hubs"; | ||
import { DefaultAzureCredential } from "@azure/identity"; | ||
|
||
// Load the .env file if it exists | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
|
||
// Define Event Hubs Endpoint and related entity name here here | ||
const eventHubsFullyQualifiedName = process.env["EVENTHUB_FQDN"] || ""; // <your-eventhubs-namespace>.servicebus.windows.net | ||
const eventHubName = process.env["EVENTHUB_NAME"] || ""; | ||
const consumerGroup = process.env["CONSUMER_GROUP_NAME"] || ""; | ||
|
||
// Define AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET of your AAD application in your environment | ||
|
||
export async function main(): Promise<void> { | ||
console.log(`Running usingAadAuth sample`); | ||
|
||
const credential = new DefaultAzureCredential(); | ||
const client = new EventHubConsumerClient( | ||
consumerGroup, | ||
eventHubsFullyQualifiedName, | ||
eventHubName, | ||
credential | ||
); | ||
/* | ||
Refer to other samples, and place your code here | ||
to send/receive events | ||
*/ | ||
await client.close(); | ||
|
||
console.log(`Exiting usingAadAuth sample`); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error("Error running sample:", error); | ||
}); |
Oops, something went wrong.