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
Copy file name to clipboardExpand all lines: articles/storage/blobs/storage-blob-change-feed-how-to.md
+85-66Lines changed: 85 additions & 66 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
---
2
2
title: Process change feed in Azure Blob Storage
3
3
titleSuffix: Azure Storage
4
-
description: Learn how to process change feed logs in a .NET client application
4
+
description: Learn how to process change feed transaction logs in a .NET client application using the Blobs Change Feed client library.
5
5
author: normesta
6
6
7
7
ms.author: normesta
8
-
ms.date: 03/03/2022
8
+
ms.date: 06/06/2024
9
9
ms.topic: article
10
10
ms.service: azure-blob-storage
11
11
ms.reviewer: sadodd
@@ -19,35 +19,66 @@ Change feed provides transaction logs of all the changes that occur to the blobs
19
19
20
20
To learn more about the change feed, see [Change feed in Azure Blob Storage](storage-blob-change-feed.md).
21
21
22
-
## Get the blob change feed processor library
22
+
## Set up your project
23
23
24
-
1. Open a command window (For example: Windows PowerShell).
25
-
2. From your project directory, install the [**Azure.Storage.Blobs.Changefeed** NuGet package](https://www.nuget.org/packages/Azure.Storage.Blobs.ChangeFeed/).
24
+
This section walks you through preparing a project to work with the Blobs Change Feed client library for .NET.
25
+
26
+
### Install packages
27
+
28
+
From your project directory, install the package for the [Azure Storage Blobs Change Feed client library for .NET](/dotnet/api/overview/azure/storage.blobs.changefeed-readme) using the `dotnet add package` command. In this example, we add the `--prerelease` flag to the command to install the latest preview version.
The code examples in this article also use the [Azure Blob Storage](/dotnet/api/azure.storage.blobs) and [Azure Identity](/dotnet/api/azure.identity) packages.
35
+
36
+
```console
37
+
dotnet add package Azure.Identity
38
+
dotnet add package Azure.Storage.Blobs
39
+
```
40
+
41
+
### Add `using` directives
42
+
43
+
Add the following `using` directives to your code file:
44
+
45
+
```csharp
46
+
usingAzure.Identity;
47
+
usingAzure.Storage.Blobs;
48
+
usingAzure.Storage.Blobs.ChangeFeed;
30
49
```
31
50
32
-
## Read records
51
+
### Create a client object
52
+
53
+
To connect the application to Blob Storage, create an instance of the `BlobServiceClient` class. The following example shows how to create a client object using `DefaultAzureCredential` for authorization. To learn more, see [Authorize access and connect to Blob Storage](storage-blob-dotnet-get-started.md#authorize-access-and-connect-to-blob-storage). To work with the change feed, you'll need Azure RBAC built-in role **Storage Blob Data Reader** or higher.
54
+
55
+
```csharp
56
+
// TODO: Replace <storage-account-name> with the name of your storage account
The client object is passed as a parameter to some of the methods shown in this article.
65
+
66
+
## Read records in the change feed
33
67
34
68
> [!NOTE]
35
69
> The change feed is an immutable and read-only entity in your storage account. Any number of applications can read and process the change feed simultaneously and independently at their own convenience. Records aren't removed from the change feed when an application reads them. The read or iteration state of each consuming reader is independent and maintained by your application only.
36
70
37
-
This example iterates through all records in the change feed, adds them to a list, and then returns that list to the caller.
71
+
The following code example iterates through all records in the change feed, adds them to a list, and then returns the list of change feed events:
You can choose to save your read position in the change feed, and then resume iterating through the records at a future time. You can save the read position by getting the change feed cursor. The cursor is a **string** and your application can save that string in any way that makes sense for your application's design (For example: to a file, or database).
110
+
You can choose to save your read position in the change feed, and then resume iterating through the records at a future time. You can save the read position by getting the change feed cursor. The cursor is a **string** and your application can save that string in any way that makes sense for your application's design, for example, to a file or database.
81
111
82
112
This example iterates through all records in the change feed, adds them to a list, and saves the cursor. The list and the cursor are returned to the caller.
// Update the change feed cursor. The cursor is not required to get each page of events,
109
-
// it is intended to be saved and used to resume iterating at a later date.
136
+
// Update the change feed cursor. The cursor is not required to get each page of events,
137
+
// it's intended to be saved and used to resume iterating at a later date.
110
138
cursor=enumerator.Current.ContinuationToken;
111
139
return (cursor, changeFeedEvents);
112
140
}
@@ -116,24 +144,23 @@ public async Task<(string, List<BlobChangeFeedEvent>)> ChangeFeedResumeWithCurso
116
144
117
145
You can choose to process change feed records as they are committed to the change feed. See [Specifications](storage-blob-change-feed.md#specifications). The change events are published to the change feed at a period of 60 seconds on average. We recommend that you poll for new changes with this period in mind when specifying your poll interval.
118
146
119
-
This example periodically polls for changes. If change records exist, this code processes those records and saves change feed cursor. That way if the process is stopped and then started again, the application can use the cursor to resume processing records where it last left off. This example saves the cursor to a local application configuration file, but your application can save it in any form that makes the most sense for your scenario.
147
+
This example periodically polls for changes. If change records exist, this code processes those records and saves change feed cursor. That way if the process is stopped and then started again, the application can use the cursor to resume processing records where it last left off. This example saves the cursor to a local file for demonstration purposes, but your application can save it in any form that makes the most sense for your scenario.
You can read records that fall within a specific time range. This example iterates through all records in the change feed that fall between 3:00 PM on March 2 2020 and 2:00 AM on August 7 2020, adds them to a list, and then returns that list to the caller.
203
+
## Read records within a specific time range
182
204
183
-
### Selecting segments for a time range
205
+
You can read records that fall within a specific time range. This example iterates through all records in the change feed that fall within a specific date and time range, adds them to a list, and returns the list:
0 commit comments