Skip to content

Ensure users get the most up to date configurations from App Configuration with sync tokens - #278

Merged
Matthew Solomon (MBSolomon) merged 64 commits into
mainfrom
msolomon/PushRefresh
Nov 15, 2021
Merged

Matthew Solomon (MBSolomon) merged 64 commits into
mainfrom
msolomon/PushRefresh

Conversation

@MBSolomon

@MBSolomon Matthew Solomon (MBSolomon) commented Oct 12, 2021

Copy link
Copy Markdown
Contributor

Problem

Replication lag can occur when users request key-values from their configuration stores. This can occur after a key-value is modified and before the replication of the modification to other regions is completed. During this time users can experience an issue where the requested key-value has not been updated yet in the requested region – Which would result in outdated key-values being sent to a user’s applications.

Solution

Through the integration of a SyncToken into the read call, the user can be certain they are receiving the most up to date configurations in their application. With the new integration, the user will also send a SyncToken to the Azure App Configuration SDK which then gets passed along to cosmos DB to ensure the most recent configurations are returned. This new solution prevents replication lag from occurring and guarantees a user will receive their most up-to-date key-values. For this we implement a new PushNotification class add two new API's:

PushNotification

public class PushNotification() {
     public Uri ResourceUri;
     public string SyncToken;
     public string EventType;
}

This class stores the ResourceUri of the resource which triggered the PushNotification, the Synchronization Token to be added to the request to the App Configuration Service, and the Type of Event which triggered the Push Notification.

TryCreatePushNotification

Using the Data, Event Type and Subject stored in the Event Grid Event this method tries to create a push notification from an Event Grid Event. If successful it populates an out PushNotification Parameter and returns “true” otherwise the parameter will be null and the method will return “false”. Implementation example:

EventGridEvent.TryCreatePushNotification(out PushNotification pushNotification)

ProcessPushNotification

This method is called by the refresher and provider to process the PushNotification. ProcessPushNotification() will invoke UpdateSyncToken() and then invoke SetDirty() to ensure the most recent configuration is provided to the user.

ProcessPushNotification(PushNotification pushNotification, TimeSpan? maxDelay)

Usage Example

ServiceBusExample

private static void RegisterRefreshEventHandler()
        {
            string serviceBusConnectionString = Environment.GetEnvironmentVariable(ServiceBusConnectionStringEnvVarName);
            string serviceBusTopic = Environment.GetEnvironmentVariable(ServiceBusTopicEnvVarName);
            string serviceBusSubscription = Environment.GetEnvironmentVariable(ServiceBusSubscriptionEnvVarName);
            SubscriptionClient serviceBusClient = new SubscriptionClient(serviceBusConnectionString, serviceBusTopic, serviceBusSubscription);
            serviceBusClient.RegisterMessageHandler(
                handler: (message, cancellationToken) =>
                {
                    EventGridEvent eventGridEvent = EventGridEvent.Parse(BinaryData.FromBytes(message.Body));

                    return Task.CompletedTask;
                },
                exceptionReceivedHandler: (exceptionargs) =>
                {
                    Console.WriteLine($"{exceptionargs.Exception}");
                    return Task.CompletedTask;
                });
        }

Comment thread .gitignore Outdated
Comment thread examples/ConsoleApplication/ConsoleApplication.csproj Outdated
Comment thread examples/ConsoleApplication/Program.cs Outdated
@MBSolomon Matthew Solomon (MBSolomon) changed the title Msolomon/push refresh Ensure users get the most up to date configurations from App Configuration with sync tokens - Fix #230 Oct 14, 2021
@MBSolomon Matthew Solomon (MBSolomon) changed the title Ensure users get the most up to date configurations from App Configuration with sync tokens - Fix #230 Ensure users get the most up to date configurations from App Configuration with sync tokens Fix #230 Oct 14, 2021
@avanigupta

Copy link
Copy Markdown
Member

Can you undo changes to this file? It only differs in whitespace.


Refers to: src/Microsoft.Azure.AppConfiguration.AspNetCore/Microsoft.Azure.AppConfiguration.AspNetCore.csproj:1 in b2e3a93. [](commit_id = b2e3a93, deletion_comment = True)

Comment thread tests/Tests.AzureAppConfiguration/PushRefreshTests.cs Outdated
Comment thread tests/Tests.AzureAppConfiguration/PushRefreshTests.cs Outdated
Comment thread tests/Tests.AzureAppConfiguration/PushRefreshTests.cs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. There are only a few minor comments to address.

@zhenlan
Zhenlan Wang (zhenlan) deleted the msolomon/PushRefresh branch December 10, 2021 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Push Refresh : Allow users to update sync token from change events

4 participants