Azure App Configuration
Any application needs to store somehow its configuration properties. How to access its own database. What are secret information’s for user authentication. And so on, and so on. There are multiple ways to do this on Microsoft Azure Cloud. One of them is to use Azure App Configuration service. As docs says:
“Azure App Configuration provides a service to centrally manage application settings and feature flags.”
It provides wide range of functionalities starting from storing simple key-value entries. Application can access those values by using dedicated NuGet package and providing connection string/access key. Second very important functionality which we will check here out will be sending events on each value change.
Event Grid
Whenever a configuration value will be change, we want to reload internal configuration dictionary within application runtime. To be able to do this, we need an event broker. Again as docs says:
“Event Grid is a highly scalable, serverless event broker that you can use to integrate applications using events.”
In our scenario, we need an Azure App Configuration subscription inside Event grid, which will be an endpoint to notify about any key-value changes. Then we will be able to attach applications to this subscription to receive events at runtime.
Azure Functions
Each application needs its own hosting platform. There are plenty of them to use. First that came to my mind when thinking about some short showcases are Azure Functions.
“Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs. Instead of worrying about deploying and maintaining servers, the cloud infrastructure provides all the up-to-date resources needed to keep your applications running.”
Working with Functions is devoid of thinking to much about infrastructure and developers can focus more on giving value to the product, then struggling with things they usually don’t like.
Design
For this short exercise we will use Azure Functions as a hosting platform. Within Azure Function App we will define two functions (you can think about it as an web endpoint). First one will be a webhook for reacting on events coming from Event Grid, which actually originally comes from Azure App Configuration service.
This way, we can have multiple hosting platform connected to the same configuration source, even written in different technologies, the only requirement is to implement Event Grid listener.
Example
After setting up all resources on the Microsoft Azure Platform, we need an Azure Function implementation to react on events coming from Event Grid. There is a dedicated trigger for Event Grid Events.
Having this in place we are ready to react on each event that will come from Event Grid. First of all we should filter by event type equal to “Microsoft.AppConfiguration.KeyValueModified”. Later we should only react to event that was triggered by changing Sentinel key that we recognize.
After all those validations we can set cached configurations dirty and try to refresh all configuration values.
Sources:
https://learn.microsoft.com/en-us/azure/azure-app-configuration/concept-app-configuration-event
https://learn.microsoft.com/en-us/azure/azure-app-configuration/howto-app-configuration-event
https://learn.microsoft.com/en-us/azure/azure-functions/event-grid-how-tos
My name is Paweł Ruciński. I am a .NET backend developer for about 9 years. Mainly interested in Azure Cloud technology and microservices architecture. Up until now I was working with Service Fabric or Azure Functions, but I also know some basics of a Docker and a Kubernetes.
I am always eager to learn new things and looking forward what acctually I can learn at Softensity.