Skip to content

Commit 4910572

Browse files
authored
Merge pull request #88706 from ealsur/users/ealsur/cfpmigrate
Cosmos DB - Code migration guide for Change Feed Processor
2 parents 5879656 + 41bc43d commit 4910572

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

articles/cosmos-db/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@
666666
href: how-to-configure-change-feed-start-time.md
667667
- name: Using the change feed estimator
668668
href: how-to-use-change-feed-estimator.md
669+
- name: Migrating from change feed processor library
670+
href: how-to-migrate-from-change-feed-library.md
669671
- name: Built-in analytics with Apache Spark
670672
items:
671673
- name: Azure Databricks Spark connector

articles/cosmos-db/change-feed-processor.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,6 @@ You are charged for RUs consumed, since data movement in and out of Cosmos conta
9292
You can now proceed to learn more about change feed processor in the following articles:
9393

9494
* [Overview of change feed](change-feed.md)
95+
* [How to migrate from the change feed processor library](how-to-migrate-from-change-feed-library.md)
9596
* [Using the change feed estimator](how-to-use-change-feed-estimator.md)
9697
* [Change feed processor start time](how-to-configure-change-feed-start-time.md)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Migrate from the change feed processor library to the Azure Cosmos DB .NET V3 SDK
3+
description: Learn how to migrate your application from using the change feed processor library to the Azure Cosmos DB SDK V3
4+
author: ealsur
5+
ms.service: cosmos-db
6+
ms.topic: conceptual
7+
ms.date: 09/17/2019
8+
ms.author: maquaran
9+
---
10+
11+
# Migrate from the change feed processor library to the Azure Cosmos DB .NET V3 SDK
12+
13+
This article describes the required steps to migrate an existing application's code that uses the [change feed processor library](https://github.com/Azure/azure-documentdb-changefeedprocessor-dotnet) to the [change feed](change-feed.md) feature in the latest version of the .NET SDK (also referred as .NET V3 SDK).
14+
15+
## Required code changes
16+
17+
The .NET V3 SDK has several breaking changes, the following are the key steps to migrate your application:
18+
19+
1. Convert the `DocumentCollectionInfo` instances into `Container` references for the monitored and leases containers.
20+
1. Customizations that use `WithProcessorOptions` should be updated to use `WithLeaseConfiguration` and `WithPollInterval` for intervals, `WithStartTime` [for start time](how-to-configure-change-feed-start-time.md), and `WithMaxItems` to define the maximum item count.
21+
1. Set the `processorName` on `GetChangeFeedProcessorBuilder` to match the value configured on `ChangeFeedProcessorOptions.LeasePrefix`, or use `string.Empty` otherwise.
22+
1. The changes are no longer delivered as a `IReadOnlyList<Document>`, instead, it's a `IReadOnlyCollection<T>` where `T` is a type you need to define, there is no base item class anymore.
23+
1. To handle the changes, you no longer need an implementation, instead you need to [define a delegate](change-feed-processor.md#implementing-the-change-feed-processor). The delegate can be a static Function or, if you need to maintain state across executions, you can create your own class and pass an instance method as delegate.
24+
25+
For example, if the original code to build the change feed processor looks as follows:
26+
27+
[!code-csharp[Main](~/samples-cosmosdb-dotnet-v3/Microsoft.Azure.Cosmos.Samples/Usage/ChangeFeed/Program.cs?name=ChangeFeedProcessorLibrary)]
28+
29+
The migrated code will look like:
30+
31+
[!code-csharp[Main](~/samples-cosmosdb-dotnet-v3/Microsoft.Azure.Cosmos.Samples/Usage/ChangeFeed/Program.cs?name=ChangeFeedProcessorMigrated)]
32+
33+
And the delegate, can be a static method:
34+
35+
[!code-csharp[Main](~/samples-cosmosdb-dotnet-v3/Microsoft.Azure.Cosmos.Samples/Usage/ChangeFeed/Program.cs?name=Delegate)]
36+
37+
## State and lease container
38+
39+
Similar to the change feed processor library, the change feed feature in .NET V3 SDK uses a [lease container](change-feed-processor.md#components-of-the-change-feed-processor) to store the state. However, the schemas are different.
40+
41+
The SDK V3 change feed processor will detect any old library state and migrate it to the new schema automatically upon the first execution of the migrated application code.
42+
43+
You can safely stop the application using the old code, migrate the code to the new version, start the migrated application, and any changes that happened while the application was stopped, will be picked up and processed by the new version.
44+
45+
> [!NOTE]
46+
> Migrations from applications using the library to the .NET V3 SEK are one-way, since the state (leases) will be migrated to the new schema. The migration is not backward compatible.
47+
48+
49+
## Additional resources
50+
51+
* [Azure Cosmos DB SDK](sql-api-sdk-dotnet.md)
52+
* [Usage samples on GitHub](https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples/Usage/ChangeFeed)
53+
* [Additional samples on GitHub](https://github.com/Azure-Samples/cosmos-dotnet-change-feed-processor)
54+
55+
## Next steps
56+
57+
You can now proceed to learn more about change feed processor in the following articles:
58+
59+
* [Overview of change feed processor](change-feed-processor.md)
60+
* [Using the change feed estimator](how-to-use-change-feed-estimator.md)
61+
* [Change feed processor start time](how-to-configure-change-feed-start-time.md)

0 commit comments

Comments
 (0)