Version: 1.2.7
This sample uses Azure Functions and Open Message Format to send real time data from the OpenWeather API to CONNECT data services. Once the Azure Function is published, every five minutes it collects current weather data for a specified list of cities, converts that data into OMF, and sends it to ADH.
The .NET Core CLI is referenced in this sample, and should be installed to run the sample from the command line.
This sample uses .NET 6.0
In order to run this sample as an Azure Function App, a subscription to Microsoft Azure is required. Note that the published Azure Function App may add to Azure subscription costs, so it should be stopped or deleted after use.
Sign up for an OpenWeather account, and get your free API key from the API keys tab of your account. Alternately, if an API key is not provided, the app will generate random, fake data for the passed list of cities.
- Open OpenWeather.sln in Microsoft Visual Studio
- Right click the OpenWeather project, and publish the function to your Azure subscription, see Microsoft docs for detailed instructions
- Set up the Configuration of the Azure Function App, this can either be done via the "Edit Azure App Services settings" button in the Publish screen after the function is published, or using the "Configuration" panel of the App Service inside the Azure Portal. The following settings must be added (these are listed in Program.cs in the
LoadConfiguration
function):OPEN_WEATHER_URI
, should behttps://api.openweathermap.org/data/2.5/weather
unless changed by OpenWeatherOPEN_WEATHER_KEY
, should be the API key from your OpenWeather accountOPEN_WEATHER_QUERIES
, should be a pipe-separated list of cities in the OpenWeather query format, likeSan Leandro,us|Philadelphia,us|Johnson City,us|Scottsdale,us
Cds_URI
, should be the host specified at the beginning of the URL in the Cds API ConsoleCds_TENANT_ID
, should be the ID that comes after/Tenants/
in the same URLCds_NAMESPACE_ID
, should be the name of the ADH Namespace to receive the dataCds_CLIENT_ID
, should be the ID of a Client Credentials Client. This client will need to have an OMF Connection configured to the specified Namespace in order to successfully send data. To configure one, pick "OMF" from the "Type" dropdown in the Connections page.Cds_CLIENT_SECRET
, should be the secret from the Client Credentials client that was specified
- Consider storing
OPEN_WEATHER_KEY
andCds_CLIENT_SECRET
in an Azure Key Vault- Create new secrets for each of these values in the Azure Key Vault
- Enable a system-managed identity for your Azure Function App Service
- Grant the App Service identity access to read secrets from the Key Vault
- Use
@Microsoft.KeyVault(SecretUri={uri})
in the Configuration values to read them from the Key Vault at runtime
- Use the
Monitor
panel of the Azure Function to verify that the Azure Function App Service is working as expected, this may require configuring Application Insights first
- If you have already published your Azure Function App, you can use the same "Application Settings" window from the "Publish" panel to specify "Local" values of the configuration values for your Azure Function, and run it locally using those settings
- Alternately, it is possible to fill in the values in appsettings.placeholder.json with the values described above, and then rename the file to
appsettings.json
- If
appsettings.json
is present and configured, from the command line, simply run:
dotnet restore
dotnet run
Note: The automated test uses the latter strategy
To run the automated test, appsettings.placeholder.json should be configured and renamed to appsettings.json
. The automated test checks that a value is present for the city San Leandro,us
, so that must be one of the cities specified in OpenWeatherQueries
.
From the command line, run
dotnet restore
dotnet test
The test sends a type, container, and data message to Cds. Then, the test checks that a value with a recent timestamp is found in CONNECT data services.
For the main Cds samples page ReadMe
For the main AVEVA samples page ReadMe