You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To process the change feed by using the pull model, create an instance of `ChangeFeedPullModelIterator`. When you initially create `ChangeFeedPullModelIterator`, you must specify a required `changeFeedStartFrom` value inside the `ChangeFeedIteratorOptions` which consists of both the starting position for reading changes and the resource(a partition key or a FeedRange) for which changes are to be fetched.
304
+
> [!NOTE]
305
+
> If no `changeFeedStartFrom` value is specified, then changefeed will be fetched for an entire container from Now().
306
+
> Currently, only [latest version](change-feed-modes.md#latest-version-change-feed-mode) is supported by JS SDK and is selected by default.
307
+
308
+
You can optionally use `maxItemCount` in `ChangeFeedIteratorOptions` to set the maximum number of items received per page.
309
+
Here's an example of how to obtain the iterator in latest version mode that returns entity objects:
If you don't supply a `FeedRange` or `PartitionKey` parameter inside `ChangeFeedStartFrom`, you can process an entire container's change feed at your own pace. Here's an example, which starts reading all changes, starting at the current time:
if (response.statusCode===StatusCodes.NotModified) {
339
+
timeout =5000;
340
+
}
341
+
else {
342
+
console.log("Result found", response.result);
343
+
timeout =0;
344
+
}
345
+
awaitwaitFor(timeout);
346
+
}
347
+
```
348
+
349
+
Because the change feed is effectively an infinite list of items that encompass all future writes and updates, the value of `hasMoreResults` is always `true`. When you try to read the change feed and there are no new changes available, you receive a response with `NotModified` status. In the preceding example, it's handled by waiting five seconds before rechecking for changes.
350
+
351
+
### Consume the changes for a partition key
352
+
353
+
In some cases, you might want to process only the changes for a specific partition key. You can obtain iterator for a specific partition key and process the changes the same way that you can for an entire container.
if (response.statusCode===StatusCodes.NotModified) {
371
+
timeout =5000;
372
+
}
373
+
else {
374
+
console.log("Result found", response.result);
375
+
timeout =0;
376
+
}
377
+
awaitwaitFor(timeout);
378
+
}
379
+
```
380
+
381
+
### Use FeedRange for parallelization
382
+
383
+
In the change feed pull model, you can use the `FeedRange` to parallelize the processing of the change feed. A `FeedRange` represents a range of partition key values.
384
+
385
+
Here's an example that shows how to get a list of ranges for your container:
386
+
387
+
```js
388
+
constranges=awaitcontainer.getFeedRanges();
389
+
```
390
+
391
+
When you get a list of `FeedRange` values for your container, you get one `FeedRange` per [physical partition](../partitioning-overview.md#physical-partitions).
392
+
393
+
By using a `FeedRange`, you can create iterator to parallelize the processing of the change feed across multiple machines or threads. Unlike the previous example that showed how to obtain a changefeed iterator for the entire container or a single partition key, you can use FeedRanges to obtain multiple iterators, which can process the change feed in parallel.
394
+
395
+
Here's a sample that shows how to read from the beginning of the container's change feed by using two hypothetical separate machines that read in parallel:
if (response.statusCode===StatusCodes.NotModified) {
443
+
timeout =5000;
444
+
}
445
+
else {
446
+
console.log("Result found", response.result);
447
+
timeout =0;
448
+
}
449
+
awaitwaitFor(timeout);
450
+
}
451
+
```
452
+
453
+
### Save continuation tokens
454
+
455
+
You can save the position of your iterator by obtaining the continuation token. A continuation token is a string value that keeps of track of your changefeed iterator last processed changes and allows the iterator to resume at this point later. The continuation token, if specified, takes precedence over the start time and start from beginning values. The following code reads through the change feed since container creation. After no more changes are available, it will persist a continuation token so that change feed consumption can be later resumed.
0 commit comments