ConfigurationClient Class

Definition

This class provides a client that contains all the operations for ConfigurationSetting in Azure App Configuration Store. Operations allowed by the client are adding, retrieving, deleting, set read-only status ConfigurationSettings, and listing settings or revision of a setting based on a SettingSelector.

Instantiating a synchronous Configuration Client

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

View ConfigurationClientBuilder for additional ways to construct the client.

public final class ConfigurationClient
Inheritance
java.lang.Object
ConfigurationClient

Inherited Members

java.lang.Object.clone() java.lang.Object.equals(java.lang.Object) java.lang.Object.finalize() java.lang.Object.getClass() java.lang.Object.hashCode() java.lang.Object.notify() java.lang.Object.notifyAll() java.lang.Object.toString() java.lang.Object.wait() java.lang.Object.wait(long) java.lang.Object.wait(long,int)

Methods

addConfigurationSetting(ConfigurationSetting setting)

Adds a configuration value in the service if that key and label does not exist. The label value of the ConfigurationSetting is optional.

Code Samples

Add a setting with the key "prodDBConnection", label "westUS" and value "db_connection".

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());
addConfigurationSetting(String key, String label, String value)

Adds a configuration value in the service if that key does not exist. The label is optional.

Code Samples

Add a setting with the key "prodDBConnection", label "westUS" and value "db_connection".

ConfigurationSetting result = configurationClient
     .addConfigurationSetting("prodDBConnection", "westUS", "db_connection");
 System.out.printf("Key: %s, Label: %s, Value: %s", result.getKey(), result.getLabel(), result.getValue());
addConfigurationSettingWithResponse(ConfigurationSetting setting, Context context)

Adds a configuration value in the service if that key and label does not exist. The label value of the ConfigurationSetting is optional.

Code Samples

Add a setting with the key "prodDBConnection", label "westUS", and value "db_connection".

Response<ConfigurationSetting> responseResultSetting = configurationClient
     .addConfigurationSettingWithResponse(
         new ConfigurationSetting()
             .setKey("prodDBConnection").setLabel("westUS").setValue("db_connection"),
         new Context(key1, value1));
 final ConfigurationSetting resultSetting = responseResultSetting.getValue();
 System.out.printf("Key: %s, Label: %s, Value: %s", resultSetting.getKey(), resultSetting.getLabel(),
     resultSetting.getValue());
deleteConfigurationSetting(ConfigurationSetting setting)

Deletes the ConfigurationSetting with a matching getKey(), and optional getLabel() and optional ETag combination.

Code Samples

Delete the setting with the key "prodDBConnection".

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

Deletes the ConfigurationSetting with a matching key and optional label combination.

Code Samples

Delete the setting with the key "prodDBConnection".

ConfigurationSetting result = configurationClient.deleteConfigurationSetting("prodDBConnection", null);
 System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());
deleteConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, Context context)

Deletes the ConfigurationSetting with a matching getKey(), and optional getLabel() and optional ETag combination. If getETag() is specified and is not the wildcard character ("*"), then the setting is only deleted if the ETag matches the current ETag; this means that no one has updated the ConfigurationSetting yet.

Code Samples

Delete the setting with the key "prodDBConnection".

Response<ConfigurationSetting> responseSetting = configurationClient.deleteConfigurationSettingWithResponse(
     new ConfigurationSetting().setKey("prodDBConnection").setLabel("westUS"),
     false, new Context(key2, value2));
 System.out.printf(
     "Key: %s, Value: %s", responseSetting.getValue().getKey(), responseSetting.getValue().getValue());
getConfigurationSetting(ConfigurationSetting setting)

Attempts to get the ConfigurationSetting with a matching getKey(), and optional getLabel(), optional acceptDateTime and optional ETag combination.

Code Samples

Retrieve the setting with the key "prodDBConnection".

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

Attempts to get a ConfigurationSetting that matches the key, and the optional label combination.

Code Samples

Retrieve the setting with the key "prodDBConnection".

ConfigurationSetting resultNoDateTime =
     configurationClient.getConfigurationSetting("prodDBConnection", null);
 System.out.printf("Key: %s, Value: %s", resultNoDateTime.getKey(), resultNoDateTime.getValue());
getConfigurationSetting(String key, String label, OffsetDateTime acceptDateTime)

Attempts to get a ConfigurationSetting that matches the key, the optional label, and the optional acceptDateTime combination.

Code Samples

Retrieve the setting with the key "prodDBConnection".

ConfigurationSetting result =
     configurationClient.getConfigurationSetting("prodDBConnection", null, null);
 System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());
getConfigurationSettingWithResponse(ConfigurationSetting setting, OffsetDateTime acceptDateTime, boolean ifChanged, Context context)

Attempts to get the ConfigurationSetting with a matching getKey(), and optional getLabel(), optional acceptDateTime and optional ETag combination.

Code Samples

Retrieve the setting with the key "prodDBConnection".

// Retrieve the setting with the key-label "prodDBConnection"-"westUS".
 Response<ConfigurationSetting> responseResultSetting = configurationClient.getConfigurationSettingWithResponse(
     new ConfigurationSetting().setKey("prodDBConnection").setLabel("westUS"),
     null, false, new Context(key1, value1));
 System.out.printf("Key: %s, Value: %s", responseResultSetting.getValue().getKey(),
     responseResultSetting.getValue().getValue());
listConfigurationSettings(SettingSelector selector)

Fetches the configuration settings that match the selector. If selector is null, then all the ConfigurationSetting are fetched with their current values.

Code Samples

Retrieve 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());
 });
listConfigurationSettings(SettingSelector selector, Context context)

Fetches the configuration settings that match the selector. If selector is null, then all the ConfigurationSetting are fetched with their current values.

Code Samples

Retrieve all settings that use the key "prodDBConnection".

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

Lists chronological/historical representation of ConfigurationSetting resource(s). Revisions are provided in descending order from their getLastModified() date. Revisions expire after a period of time, see Pricing for more information. If selector is null, then all the ConfigurationSetting are fetched in their current state. Otherwise, the results returned match the parameters given in selector.

Code Samples

Retrieve all revisions of the setting that has the key "prodDBConnection".

SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection");
 client.listRevisions(settingSelector).streamByPage().forEach(resp -> {
     System.out.printf("Response headers are %s. Url %s  and status code %d %n", resp.getHeaders(),
         resp.getRequest().getUrl(), resp.getStatusCode());
     resp.getItems().forEach(value -> {
         System.out.printf("Response value is %d %n", value);
     });
 });
listRevisions(SettingSelector selector, Context context)

Lists chronological/historical representation of ConfigurationSetting resource(s). Revisions are provided in descending order from their getLastModified() date. Revisions expire after a period of time, see Pricing for more information. If selector is null, then all the ConfigurationSetting are fetched in their current state. Otherwise, the results returned match the parameters given in selector.

Code Samples

Retrieve all revisions of the setting that has the key "prodDBConnection".

SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection");
 Context ctx = new Context(key2, value2);
 configurationClient.listRevisions(settingSelector, ctx).forEach(setting -> {
     System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
 });
setConfigurationSetting(ConfigurationSetting setting)

Creates or updates a configuration value in the service. Partial updates are not supported and the entire configuration setting is updated.

Code Samples

Add a setting with the key "prodDBConnection" and value "db_connection".

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());
setConfigurationSetting(String key, String label, String value)

Creates or updates a configuration value in the service with the given key and. the label is optional.

Code Samples

Add a setting with the key "prodDBConnection", "westUS" and value "db_connection".

Update setting's value "db_connection" to "updated_db_connection"

ConfigurationSetting result = configurationClient
     .setConfigurationSetting("prodDBConnection", "westUS", "db_connection");
 System.out.printf("Key: %s, Label: %s, Value: %s", result.getKey(), result.getLabel(), result.getValue());
 
 // Update the value of the setting to "updated_db_connection".
 result = configurationClient.setConfigurationSetting(
     "prodDBConnection", "westUS", "updated_db_connection");
 System.out.printf("Key: %s, Label: %s, Value: %s", result.getKey(), result.getLabel(), result.getValue());
setConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, Context context)

Creates or updates a configuration value in the service. Partial updates are not supported and the entire configuration setting is updated. If getETag() is specified, the configuration value is updated if the current setting's ETag matches. If the ETag's value is equal to the wildcard character ("*"), the setting will always be updated.

Code Samples

Add a setting with the key "prodDBConnection" and value "db_connection".

Update setting's value "db_connection" to "updated_db_connection"

// Add a setting with the key "prodDBConnection", label "westUS", and value "db_connection"
 Response<ConfigurationSetting> responseSetting = configurationClient.setConfigurationSettingWithResponse(
     new ConfigurationSetting().setKey("prodDBConnection").setLabel("westUS").setValue("db_connection"),
     false,
     new Context(key2, value2));
 final ConfigurationSetting initSetting = responseSetting.getValue();
 System.out.printf("Key: %s, Value: %s", initSetting.getKey(), initSetting.getValue());
 
 // Update the value of the setting to "updated_db_connection".
 responseSetting = configurationClient.setConfigurationSettingWithResponse(
     new ConfigurationSetting().setKey("prodDBConnection").setLabel("westUS").setValue("updated_db_connection"),
     false,
     new Context(key2, value2));
 final ConfigurationSetting updatedSetting = responseSetting.getValue();
 System.out.printf("Key: %s, Value: %s", updatedSetting.getKey(), updatedSetting.getValue());
setReadOnly(ConfigurationSetting setting, boolean isReadOnly)

Sets the read-only status for the ConfigurationSetting.

Code Samples

Set the setting to read-only with the key-label "prodDBConnection"-"westUS".

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

Clear read-only of the setting with the key-label "prodDBConnection"-"westUS".

ConfigurationSetting setting = configurationClient.setReadOnly(
     new ConfigurationSetting().setKey("prodDBConnection").setLabel("westUS"), false);
 System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
setReadOnly(String key, String label, boolean isReadOnly)

Sets the read-only status for the ConfigurationSetting that matches the key, the optional label.

Code Samples

Set the setting to read-only with the key-label "prodDBConnection"-"westUS".

ConfigurationSetting result = configurationClient.setReadOnly("prodDBConnection", "westUS", true);
 System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());

Clear read-only of the setting with the key-label "prodDBConnection"-"westUS".

ConfigurationSetting result = configurationClient.setReadOnly("prodDBConnection", "westUS", false);
 System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());
setReadOnlyWithResponse(ConfigurationSetting setting, boolean isReadOnly, Context context)

Sets the read-only status for the ConfigurationSetting.

Code Samples

Set the setting to read-only with the key-label "prodDBConnection"-"westUS".

ConfigurationSetting resultSetting = configurationClient.setReadOnlyWithResponse(
     new ConfigurationSetting().setKey("prodDBConnection").setLabel("westUS"), true, Context.NONE)
     .getValue();
 System.out.printf("Key: %s, Value: %s", resultSetting.getKey(), resultSetting.getValue());

Clear read-only of the setting with the key-label "prodDBConnection"-"westUS".

Response<ConfigurationSetting> responseSetting = configurationClient
     .setConfigurationSettingWithResponse(
         new ConfigurationSetting().setKey("prodDBConnection").setLabel("westUS"), false,
         new Context(key2, value2));
 System.out.printf("Key: %s, Value: %s", responseSetting.getValue().getKey(),
     responseSetting.getValue().getValue());
updateSyncToken(String token)

Adds an external synchronization token to ensure service requests receive up-to-date values.

Applies to