JavaScript 用 Azure Storage Blob Change Feed クライアント ライブラリ - バージョン 12.0.0-preview.4
サーバー バージョン: 2019-12-12 以降。
変更フィードは、ストレージ アカウント内の BLOB と BLOB メタデータに対して発生するすべての変更の順序付き、保証、持続性、不変、読み取り専用のトランザクション ログを提供します。 クライアント アプリケーションは、いつでもこれらのログを読み取ることができます。 変更フィードを使用すると、低コストで、BLOB ストレージ アカウントで発生する変更イベントを処理する効率的でスケーラブルなソリューションを構築できます。
このプロジェクトには、変更フィードを簡単に使用できる JavaScript のクライアント ライブラリが用意されています。
このパッケージのクライアント ライブラリを使用して、次の操作を行います。
- 変更フィード イベントの読み取り (すべてまたは時間範囲内)
- 保存された位置からのイベントの読み取りを再開する
主要リンク:
- Node.js の LTS バージョン
- Safari、Chrome、Edge、Firefox の最新バージョン。
詳細については、Microsoft のサポート ポリシーを参照してください。
JavaScript 用の Azure Storage Blob Change Feed クライアント ライブラリをインストールする推奨される方法は、npm パッケージ マネージャーを使用することです。 ターミナル ウィンドウに次のように入力します。
npm install @azure/storage-blob-changefeed
このライブラリでは、認証済み を使用して初期化します BlobServiceClient
。 を認証する方法については、 ストレージ BLOB に関するページを BlobServiceClient
参照してください。
現時点では、このライブラリは Node.js とのみ互換性があります。
変更フィードは、Standard BLOB の料金コストで、ストレージ アカウントの特別なコンテナーに BLOB として格納されます。 これらのファイルの保持期間は、要件に基づいて制御できます。 変更イベントは、Apache Avro 形式仕様のレコードとして変更フィードに追加されます。これは、インライン スキーマを使用して豊富なデータ構造を提供するコンパクトで高速なバイナリ形式です。 この形式は Hadoop エコシステム、Stream Analytics、Azure Data Factory で幅広く使用されています。
このライブラリには、変更イベントのフェッチに使用できるクライアントが用意されています。
には BlobChangeFeedClient
、初期化とほとんど同じパラメーターが BlobServiceClient
必要です。 BLOB サービス クライアントを作成する方法については、 ストレージ BLOB に関するページを参照してください。 StorageSharedKeyCredential
を使用した例を次に示します。
const { StorageSharedKeyCredential } = require("@azure/storage-blob");
const { BlobChangeFeedClient } = require("@azure/storage-blob-changefeed");
// Enter your storage account name and shared key
const account = "<account>";
const accountKey = "<accountkey>";
// Use StorageSharedKeyCredential with storage account and account key
// StorageSharedKeyCredential is only available in Node.js runtime, not in browsers
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
const changeFeedClient = new BlobChangeFeedClient(
// When using AnonymousCredential, following url should include a valid SAS or support public access
`https://${account}.blob.core.windows.net`,
sharedKeyCredential
);
変更イベントを反復処理する反復子を取得するには、 を使用 BlobChangeFeedClient.listChanges()
します。
const { BlobChangeFeedEvent } = require("@azure/storage-blob-changefeed");
let changeFeedEvents = [];
for await (const event of changeFeedClient.listChanges()) {
changeFeedEvents.push(event);
}
ページ別。
const { BlobChangeFeedEvent } = require("@azure/storage-blob-changefeed");
let changeFeedEvents = [];
for await (const eventPage of changeFeedClient.listChanges().byPage()) {
for (const event of eventPage.events) {
changeFeedEvents.push(event);
}
}
const { BlobChangeFeedEvent } = require("@azure/storage-blob-changefeed");
let changeFeedEvents = [];
const firstPage = await changeFeedClient
.listChanges()
.byPage({ maxPageSize: 10 })
.next();
for (const event of firstPage.value.events) {
changeFeedEvents.push(event);
}
// Resume iterating from the previous position with the continuationToken.
for await (const eventPage of changeFeedClient
.listChanges()
.byPage({ continuationToken: firstPage.value.continuationToken })) {
for (const event of eventPage.events) {
changeFeedEvents.push(event);
}
}
開始時刻と終了時刻を に渡して BlobChangeFeedClient.listChanges()
、時間範囲内のイベントをフェッチします。
現時点では、変更フィード クライアントは開始時刻を最も近い時間に切り捨て、終了時刻を次の 1 時間に丸めます。
const { BlobChangeFeedEvent } = require("@azure/storage-blob-changefeed");
const start = new Date(Date.UTC(2020, 1, 21, 22, 30, 0)); // will be rounded down to 22:00
const end = new Date(Date.UTC(2020, 4, 8, 21, 10, 0)); // will be rounded up to 22:00
let changeFeedEvents = [];
// You can also provide just a start or end time.
for await (const event of changeFeedClient.listChanges({ start, end })) {
changeFeedEvents.push(event);
}
ログの記録を有効にすると、エラーに関する有用な情報を明らかにするのに役立つ場合があります。 HTTP 要求と応答のログを表示するには、環境変数 AZURE_LOG_LEVEL
を info
に設定します。 または、@azure/logger
で setLogLevel
を呼び出して、実行時にログ記録を有効にすることもできます。
import { setLogLevel } from "@azure/logger";
setLogLevel("info");
その他のコード サンプル:
- Blob Storage 変更フィードのサンプル (JavaScript)
- Blob Storage 変更フィードのサンプル (TypeScript)
- Blob Storage 変更フィードのテスト ケース
このライブラリに投稿する場合、コードをビルドしてテストする方法の詳細については、投稿ガイドを参照してください。
ストレージ ライブラリのテスト環境を設定する方法の詳細については、「ストレージ 固有のガイド 」も参照してください。
Azure SDK for JavaScript に関するフィードバック
Azure SDK for JavaScript はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。