|
| 1 | +--- |
| 2 | +title: Migrate from the change feed processor library to the Azure Cosmos DB SDK V3 |
| 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/10/2019 |
| 8 | +ms.author: maquaran |
| 9 | +--- |
| 10 | + |
| 11 | +# Migrate from the change feed processor library to the Azure Cosmos DB SDK V3 |
| 12 | + |
| 13 | +This article describes the required steps to migrate an existing application's code that uses the [library](https://github.com/Azure/azure-documentdb-changefeedprocessor-dotnet) to consume the [change feed](change-feed.md) to the SDK V3. |
| 14 | + |
| 15 | +## Required code changes |
| 16 | + |
| 17 | +The SDK V3 includes several breaking changes in the public APIs. The main steps to address during the migration are: |
| 18 | + |
| 19 | +1. Convert `DocumentCollectionInfo` instances into `Container` references for the monitored and leases containers. |
| 20 | +1. Customizations that were using `WithProcessorOptions` should be using `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. If specifying `ChangeFeedProcessorOptions.LeasePrefix`, use that same value as the `processorName` on `GetChangeFeedProcessorBuilder`, 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 Observer implementation, [just a delegate](change-feed-processor.md#implementing-the-change-feed-processor). This delegate can be a simple 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 is building the change feed processor like this: |
| 26 | + |
| 27 | +[!code-csharp[Main](~/samples-cosmosdb-dotnet-v3/Microsoft.Azure.Cosmos.Samples/Usage/ChangeFeed/Program.cs?name=ChangeFeedProcessorLibrary)] |
| 28 | + |
| 29 | +The migrated code would 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 simply 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 | +The change feed processor uses a [lease container](change-feed-processor.md#components-of-the-change-feed-processor) to store state, and this is also valid for the library. |
| 40 | + |
| 41 | +The state created by the library (the lease documents) has a different schema than the SDK V3 but it will be **migrated automatically** upon the first execution of the migrated application code. This means that 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. |
| 42 | + |
| 43 | +> [!NOTE] |
| 44 | +> Migrations from applications using the library to the SDK V3 are one-way, since the state (leases) will be migrated to the new schema that is not backward compatible. |
| 45 | +
|
| 46 | + |
| 47 | +## Additional resources |
| 48 | + |
| 49 | +* [Azure Cosmos DB SDK](sql-api-sdk-dotnet.md) |
| 50 | +* [Usage samples on GitHub](https://github.com/Azure/azure-cosmos-dotnet-v3/tree/master/Microsoft.Azure.Cosmos.Samples/Usage/ChangeFeed) |
| 51 | +* [Additional samples on GitHub](https://github.com/Azure-Samples/cosmos-dotnet-change-feed-processor) |
| 52 | + |
| 53 | +## Next steps |
| 54 | + |
| 55 | +You can now proceed to learn more about change feed processor in the following articles: |
| 56 | + |
| 57 | +* [Overview of change feed processor](change-feed-processor.md) |
| 58 | +* [Using the change feed estimator](how-to-use-change-feed-estimator.md) |
| 59 | +* [Change feed processor start time](how-to-configure-change-feed-start-time.md) |
0 commit comments