Package com.azure.data.appconfiguration


package com.azure.data.appconfiguration

Azure App Configuration Service is a managed service provided by Microsoft Azure that allows developers to centralize configuration settings for their applications. With App Configuration, developers can store and manage application settings, feature flags, and other configuration data in one central location. This simplifies the management of configuration settings and makes it easy to update configuration values for multiple applications.

The Azure App Configuration library is a client library that provides Java developers with a simple and easy-to-use interface for accessing and using the Azure App Configuration Service. This library allows developers to easily manage their application's configuration settings, feature flags, and other configuration data stored in the Azure App Configuration Service.

Getting Started

In order to interact with the App Configuration service you'll need to create an instance of the Configuration Client class. To make this possible you'll need the connection string of the configuration store. Alternatively, you can use AAD authentication via Azure Identity to connect to the service.

  1. Connection string, see connectionString.
  2. Azure Active Directory, see TokenCredential.

Sample: Construct Asynchronous Configuration Client with Connection String

The following code sample demonstrates the creation of a ConfigurationAsyncClient, using the ConfigurationClientBuilder to configure it with a connection string.

 ConfigurationAsyncClient configurationAsyncClient = new ConfigurationClientBuilder()
     .connectionString(connectionString)
     .buildAsyncClient();
 

Sample: Construct Synchronous Configuration Client with Connection String

The following code sample demonstrates the creation of a ConfigurationClient, using the ConfigurationClientBuilder to configure it with a connection string.

 ConfigurationClient configurationClient = new ConfigurationClientBuilder()
     .connectionString(connectionString)
     .buildClient();
 

App Configuration support multiple operations, such as create, update, retrieve, and delete a configuration setting. See methods in client level class below to explore all capabilities that library provides.

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.



Add Configuration Setting

The addConfigurationSetting method can be used to add a configuration setting in the Azure App Configuration.

The sample below shows how to add a setting with the key "prodDBConnection", label "westUS" and value "db_connection" using ConfigurationClient.

 ConfigurationSetting setting = configurationClient.addConfigurationSetting(new ConfigurationSetting()
     .setKey("prodDBConnection")
     .setLabel("westUS")
     .setValue("db_connection"));
 System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue());
 

Note: For asynchronous sample, refer to ConfigurationAsyncClient.



Update Configuration Setting

The setConfigurationSetting method can be used to update a configuration setting in the Azure App Configuration.

The sample below shows how to update setting's value "db_connection" to "updated_db_connection"

 ConfigurationSetting setting = configurationClient.setConfigurationSetting(new ConfigurationSetting()
     .setKey("prodDBConnection")
     .setLabel("westUS")
     .setValue("db_connection"));
 System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue());

 // Update the value of the setting to "updated_db_connection".
 setting = configurationClient.setConfigurationSetting(new ConfigurationSetting()
     .setKey("prodDBConnection")
     .setLabel("westUS")
     .setValue("updated_db_connection"));
 System.out.printf("Key: %s, Label: %s, Value: %s", setting.getKey(), setting.getLabel(), setting.getValue());
 

Note: For asynchronous sample, refer to ConfigurationAsyncClient.



Get Configuration Setting

The getConfigurationSetting method can be used to get a configuration setting in the Azure App Configuration.

The sample below shows how to retrieve the setting with the key "prodDBConnection".

 ConfigurationSetting setting = configurationClient.getConfigurationSetting(new ConfigurationSetting()
     .setKey("prodDBConnection")
     .setLabel("westUS"));
 System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
 

Note: For asynchronous sample, refer to ConfigurationAsyncClient.



Delete Configuration Setting

The deleteConfigurationSetting method can be used to delete a configuration setting in the Azure App Configuration.

The sample below shows how to delete the setting with the key "prodDBConnection".

 ConfigurationSetting setting = configurationClient.deleteConfigurationSetting(new ConfigurationSetting()
     .setKey("prodDBConnection")
     .setLabel("westUS"));
 System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
 

Note: For asynchronous sample, refer to ConfigurationAsyncClient.



List Configuration Settings

The listConfigurationSettings method can be used to list configuration settings in the Azure App Configuration.

The sample below shows how to list all settings that use the key "prodDBConnection".

 SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection");
 configurationClient.listConfigurationSettings(settingSelector).forEach(setting -> {
     System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
 });
 

Note: For asynchronous sample, refer to ConfigurationAsyncClient.

See Also: