Skip to content

Commit

Permalink
update samples for avad change feed delete operation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcocchi committed Dec 4, 2024
1 parent 292771d commit 8f5c371
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ static async Task<string> CreateAllVersionsAndDeletesChangeFeedIterator(Containe
Console.WriteLine("Creating ChangeFeedIterator to read the change feed in All Versions and Deletes mode.");

// <InitializeFeedIterator>
using (FeedIterator<ChangeFeedItem<Item>> allVersionsIterator = container
.GetChangeFeedIterator<ChangeFeedItem<Item>>(ChangeFeedStartFrom.Now(), ChangeFeedMode.AllVersionsAndDeletes))
using (FeedIterator<dynamic> allVersionsIterator = container
.GetChangeFeedIterator<dynamic>(ChangeFeedStartFrom.Now(), ChangeFeedMode.AllVersionsAndDeletes))
{
while (allVersionsIterator.HasMoreResults)
{
FeedResponse<ChangeFeedItem<Item>> response = await allVersionsIterator.ReadNextAsync();
FeedResponse<dynamic> response = await allVersionsIterator.ReadNextAsync();

if (response.StatusCode == HttpStatusCode.NotModified)
{
Expand Down Expand Up @@ -134,11 +134,11 @@ static async Task ReadAllVersionsAndDeletesChangeFeed(Container container, strin
Console.WriteLine("Press any key to stop.");

// <ReadAllVersionsAndDeletesChanges>
using (FeedIterator<ChangeFeedItem<Item>> allVersionsIterator = container.GetChangeFeedIterator<ChangeFeedItem<Item>>(ChangeFeedStartFrom.ContinuationToken(allVersionsContinuationToken), ChangeFeedMode.AllVersionsAndDeletes, new ChangeFeedRequestOptions { PageSizeHint = 10 }))
using (FeedIterator<dynamic> allVersionsIterator = container.GetChangeFeedIterator<dynamic>(ChangeFeedStartFrom.ContinuationToken(allVersionsContinuationToken), ChangeFeedMode.AllVersionsAndDeletes, new ChangeFeedRequestOptions { PageSizeHint = 10 }))
{
while (allVersionsIterator.HasMoreResults)
{
FeedResponse<ChangeFeedItem<Item>> response = await allVersionsIterator.ReadNextAsync();
FeedResponse<dynamic> response = await allVersionsIterator.ReadNextAsync();

if (response.StatusCode == HttpStatusCode.NotModified)
{
Expand All @@ -147,25 +147,21 @@ static async Task ReadAllVersionsAndDeletesChangeFeed(Container container, strin
}
else
{
foreach (ChangeFeedItem<Item> item in response)
foreach (dynamic item in response)
{
// if operaiton is delete
if (item.Metadata.OperationType == ChangeFeedOperationType.Delete)
if (item.metadata.operationType == "delete")
{
if (item.Metadata.IsTimeToLiveExpired == true)
{
Console.WriteLine($"Operation: {item.Metadata.OperationType} (due to TTL). Item id: {item.Previous.Id}. Previous value: {item.Previous.Value}");
}
else
{
Console.WriteLine($"Operation: {item.Metadata.OperationType} (not due to TTL). Item id: {item.Previous.Id}. Previous value: {item.Previous.Value}");
}
bool isTTL = (item.metadata?.timeToLiveExpired == null) ? false : true;
Console.WriteLine($"Operation: {item.metadata.operationType}. Item id: {item.metadata.id}. Due to ttl: {isTTL}");
}
// if operation is create or replace
else
{
Console.WriteLine($"Operation: {item.Metadata.OperationType}. Item id: {item.Current.Id}. Current value: {item.Current.Value}");
Console.WriteLine($"Operation: {item.metadata.operationType}. Item id: {item.current.Id}. Current value: {item.current.Value}");
}

Console.WriteLine($"{item}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static async Task HandleChangesAsync(ChangeFeedProcessorContext context, IReadOn
{
if (item.Metadata.OperationType == ChangeFeedOperationType.Delete)
{
Console.WriteLine($"\tDetected {item.Metadata.OperationType} operation for item with id {item.Previous.id}.");
Console.WriteLine($"\tDetected {item.Metadata.OperationType} operation for item.");
}
else
{
Expand Down

0 comments on commit 8f5c371

Please sign in to comment.