forked from Azure/azure-sdk-for-js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PR CI step to build samples (Azure#12715)
* Add PR CI step to build samples * Made a change to rush-runner * Fixed an issue with rush-runner patch * Repaired metricsadvisor and anomalydetector samples builds * Repaired storage samples build scripts, added skip to storage-internal-avro * Added skips to core packages without samples * Resolved conflicting options in identity samples * Skipped broken test scripts * pnpm-lock * [eventhubs-checkpointstore-blob] fix build:samples script (#3) * [event-processor-host] fix build:samples script * Revert sorting of package.json script entries * Fixed merge artifact in dev-tool package.json * pnpm-lock * Revert formatting changes to anomalydetector * Run build phase with transitive dependencies. * Add stub build:samples commands for synapse * Added samples build setup for tables * Repaired two broken links in EPH Co-authored-by: chradek <[email protected]> Co-authored-by: chradek <[email protected]>
- Loading branch information
1 parent
af4c58e
commit 6ffd578
Showing
55 changed files
with
1,294 additions
and
154 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
33 changes: 33 additions & 0 deletions
33
sdk/eventhub/event-processor-host/samples/javascript/README.md
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,33 @@ | ||
## Getting started with samples | ||
|
||
## Install the library | ||
|
||
Run the below in your samples folder to install the npm package for Event Processor Host library. | ||
|
||
```bash | ||
npm install @azure/event-processor-host | ||
``` | ||
|
||
## Get connection string & Event Hubs name | ||
|
||
- In the [Azure Portal](https://portal.azure.com), go to **Dashboard > Event Hubs > _your-eventhubs-namespace_**. | ||
- If you don't have a Event Hubs resource, then Here are the docs which would help you create a EventHubs/Iothub resources in the portal: | ||
- [Azure Event Hubs - NodeJS DOCS](https://docs.microsoft.com/azure/event-hubs/event-hubs-node-get-started-send). | ||
- [Azure IoT Hubs - NodeJS DOCS](https://docs.microsoft.com/azure/iot-hub/iot-hub-node-node-module-twin-getstarted). | ||
- Note down the "Primary Connection String" of **RootManageSharedAccessKey** at **Shared access policies** under **Settings** tab. | ||
- Find the "Event Hubs" tab right under "Entities" at **_your-eventhubs-namespace_**, create a Event Hub and note down its name. | ||
> _Note : **RootManageSharedAccessKey** is automatically created for the namespace and has permissions for the entire namespace. If you want to use restricted access, refer [Shared Access Signatures](https://docs.microsoft.com/rest/api/eventhub/generate-sas-token), create the Access Keys exclusive to the specific Event Hubs._ | ||
- You would also need an Azure Storage Account when working with Event Processor Host. The docs are at | ||
[Create a storage account](https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal). After the storage account is created, find the connection string at **Access keys** tab in the **Settings** section. | ||
|
||
Before running a sample, update it with the connection string and the hub name you have noted down above. | ||
|
||
## Running a sample | ||
|
||
Copy the sample to your samples folder and use `node` to run it. | ||
|
||
```bash | ||
node sample.js | ||
``` | ||
|
||
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Feventhub%2Fevent-processor-host%2Fsamples%2FREADME.png) |
106 changes: 106 additions & 0 deletions
106
sdk/eventhub/event-processor-host/samples/javascript/iothubEph.js
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,106 @@ | ||
/* | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the MIT Licence. | ||
This sample demonstrates how to use Event Processor Host to receive events from all partitions | ||
of an IoTHub instance. It also shows how to checkpoint metadata for received events at regular | ||
intervals in an Azure Storage Blob. | ||
*/ | ||
|
||
const { EventProcessorHost, delay } = require("@azure/event-processor-host"); | ||
|
||
// Define IoT Hub and storage connection strings here | ||
const iotConnectionString = ""; | ||
const storageConnectionString = ""; | ||
|
||
// Use `createHostName` to create a unique name based on given prefix to use different storage containers on each run if needed. | ||
const storageContainerName = EventProcessorHost.createHostName("iothub-container"); | ||
const ephName = "my-iothub-eph"; | ||
|
||
async function main() { | ||
// Start eph. | ||
const eph = await startEph(ephName); | ||
// Sleeeping for 90 seconds. This will give time for eph to receive messages. | ||
await delay(90000); | ||
// After 90 seconds stop eph. | ||
await stopEph(eph); | ||
} | ||
|
||
main().catch((err) => { | ||
console.log("Exiting from main() due to an error: %O.", err); | ||
}); | ||
|
||
/** | ||
* Creates an EPH with the given name and starts the EPH. | ||
* @param ephName The name of the EPH. | ||
* @returns {Promise<EventProcessorHost>} Promise<EventProcessorHost> | ||
*/ | ||
async function startEph(ephName) { | ||
// Create an Event Processor Host from an IotHub ConnectionString | ||
const eph = await EventProcessorHost.createFromIotHubConnectionString( | ||
ephName, | ||
storageConnectionString, | ||
storageContainerName, | ||
iotConnectionString, | ||
{ | ||
onEphError: (error) => { | ||
console.log("[%s] Error: %O", ephName, error); | ||
} | ||
} | ||
); | ||
// Message handler | ||
const partionCount = {}; | ||
const onMessage = async (context, event) => { | ||
!partionCount[context.partitionId] | ||
? (partionCount[context.partitionId] = 1) | ||
: partionCount[context.partitionId]++; | ||
console.log( | ||
"[%s] %d - Received message from partition: '%s', offset: '%s'", | ||
ephName, | ||
partionCount[context.partitionId], | ||
context.partitionId, | ||
event.offset | ||
); | ||
// Checkpointing every 100th event received for a given partition. | ||
if (partionCount[context.partitionId] % 100 === 0) { | ||
try { | ||
console.log( | ||
"[%s] EPH is currently receiving messages from partitions: %O", | ||
ephName, | ||
eph.receivingFromPartitions | ||
); | ||
await context.checkpointFromEventData(event); | ||
console.log( | ||
"[%s] Successfully checkpointed message number %d", | ||
ephName, | ||
partionCount[context.partitionId] | ||
); | ||
} catch (err) { | ||
console.log( | ||
"[%s] An error occurred while checkpointing msg number %d: %O", | ||
ephName, | ||
partionCount[context.partitionId], | ||
err | ||
); | ||
} | ||
} | ||
}; | ||
// Error handler | ||
const onError = (error) => { | ||
console.log("[%s] Received Error: %O", ephName, error); | ||
}; | ||
console.log("Starting the EPH - %s", ephName); | ||
await eph.start(onMessage, onError); | ||
return eph; | ||
} | ||
|
||
/** | ||
* Stops the given EventProcessorHost. | ||
* @param eph The event processor host. | ||
* @returns {Promise<void>} Promise<void> | ||
*/ | ||
async function stopEph(eph) { | ||
console.log("Stopping the EPH - '%s'.", eph.hostName); | ||
await eph.stop(); | ||
console.log("Successfully stopped the EPH - '%s'.", eph.hostName); | ||
} |
Oops, something went wrong.