Condividi tramite


ChangeFeedPullModelIterator interface

Usare Items.getChangeFeedIterator() per restituire un iteratore in grado di scorrere tutte le modifiche per una chiave di partizione, un intervallo di feed o un intero contenitore.

Proprietà

hasMoreResults

Restituisce sempre true, changefeed è un flusso infinito.

Metodi

getAsyncIterator()

Ottiene un iteratore asincrono che restituirà i risultati del feed di modifiche.

esempio di

Ottenere il changefeed per un intero contenitore da ora

import { CosmosClient, ChangeFeedStartFrom } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const options = { changeFeedStartFrom: ChangeFeedStartFrom.Now() };
for await (const results of container.items.getChangeFeedIterator(options).getAsyncIterator()) {
  // Process result
  for (const resource of results.result) {
    console.log(resource);
  }
}
readNext()

Restituisce il set di risultati successivo per il feed di modifiche.

esempio di

import {
  CosmosClient,
  PartitionKeyDefinitionVersion,
  PartitionKeyKind,
  ChangeFeedStartFrom,
} from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const containerDefinition = {
  id: "Test Database",
  partitionKey: {
    paths: ["/name", "/address/zip"],
    version: PartitionKeyDefinitionVersion.V2,
    kind: PartitionKeyKind.MultiHash,
  },
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

const partitionKey = "some-partition-Key-value";
const options = {
  changeFeedStartFrom: ChangeFeedStartFrom.Beginning(partitionKey),
};

const iterator = container.items.getChangeFeedIterator(options);

while (iterator.hasMoreResults) {
  const response = await iterator.readNext();
  // process this response
}

Dettagli proprietà

hasMoreResults

Restituisce sempre true, changefeed è un flusso infinito.

hasMoreResults: boolean

Valore della proprietà

boolean

Dettagli metodo

getAsyncIterator()

Ottiene un iteratore asincrono che restituirà i risultati del feed di modifiche.

esempio di

Ottenere il changefeed per un intero contenitore da ora

import { CosmosClient, ChangeFeedStartFrom } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const options = { changeFeedStartFrom: ChangeFeedStartFrom.Now() };
for await (const results of container.items.getChangeFeedIterator(options).getAsyncIterator()) {
  // Process result
  for (const resource of results.result) {
    console.log(resource);
  }
}
function getAsyncIterator(): AsyncIterable<ChangeFeedIteratorResponse<(T & Resource)[]>>

Restituisce

AsyncIterable<ChangeFeedIteratorResponse<(T & Resource)[]>>

readNext()

Restituisce il set di risultati successivo per il feed di modifiche.

esempio di

import {
  CosmosClient,
  PartitionKeyDefinitionVersion,
  PartitionKeyKind,
  ChangeFeedStartFrom,
} from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const containerDefinition = {
  id: "Test Database",
  partitionKey: {
    paths: ["/name", "/address/zip"],
    version: PartitionKeyDefinitionVersion.V2,
    kind: PartitionKeyKind.MultiHash,
  },
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

const partitionKey = "some-partition-Key-value";
const options = {
  changeFeedStartFrom: ChangeFeedStartFrom.Beginning(partitionKey),
};

const iterator = container.items.getChangeFeedIterator(options);

while (iterator.hasMoreResults) {
  const response = await iterator.readNext();
  // process this response
}
function readNext(): Promise<ChangeFeedIteratorResponse<(T & Resource)[]>>

Restituisce