Freigeben über


ConfigurationClient Class

  • java.lang.Object
    • com.azure.data.appconfiguration.ConfigurationClient

public final class ConfigurationClient

This class provides a client that contains all the operations for ConfigurationSetting, FeatureFlagConfigurationSetting or SecretReferenceConfigurationSetting 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.

Additionally, this class allows to add an external synchronization token to ensure service requests receive up-to-date values. Use the updateSyncToken(String token) method.

Getting Started

In order to interact with the App Configuration service you'll need to create an instance of the ConfigurationClient 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(String connectionString).
  2. Azure Active Directory, see credential(TokenCredential tokenCredential).

Instantiating a synchronous Configuration Client

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

View ConfigurationClientBuilder for additional ways to construct the client.

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(ConfigurationSetting setting) 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(ConfigurationSetting setting) 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(ConfigurationSetting setting) 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(ConfigurationSetting setting) 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.


Set the Configuration Setting to read-only

The setReadOnly(ConfigurationSetting setting, boolean isReadOnly) method can be used to conditionally set a configuration setting to read-only in the Azure App Configuration.

The sample below shows how to conditionally set the setting to read-only with the key "prodDBConnection".

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

Note: For asynchronous sample, refer to ConfigurationAsyncClient.


Clear read-only of the Configuration Setting

The setReadOnly(ConfigurationSetting setting, boolean isReadOnly) method can be used to conditionally clear read-only of the setting in the Azure App Configuration.

The sample below shows how to conditionally clear read-only of the setting with the key "prodDBConnection".

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

Note: For asynchronous sample, refer to ConfigurationAsyncClient.


List Configuration Settings

The listConfigurationSettings(SettingSelector selector) 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.


List revisions of a Configuration Setting

The listRevisions(SettingSelector selector) method can be used to list all revisions of a configuration setting in the Azure App Configuration.

The sample below shows how to list all revision of a setting that use the key "prodDBConnection".

SettingSelector settingSelector = new SettingSelector().setKeyFilter("prodDBConnection");
 configurationClient.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);
     });
 });

Note: For asynchronous sample, refer to ConfigurationAsyncClient.

Method Summary

Modifier and Type Method and Description
ConfigurationSetting addConfigurationSetting(ConfigurationSetting setting)

Adds a configuration value in the service if that key and label does not exist.

ConfigurationSetting addConfigurationSetting(String key, String label, String value)

Adds a configuration value in the service if that key does not exist.

Response<ConfigurationSetting> addConfigurationSettingWithResponse(ConfigurationSetting setting, Context context)

Adds a configuration value in the service if that key and label does not exist.

ConfigurationSnapshot archiveSnapshot(String snapshotName)

Update a snapshot status from READY to ARCHIVED.

Response<ConfigurationSnapshot> archiveSnapshotWithResponse(String snapshotName, MatchConditions matchConditions, Context context)

Update a snapshot status from READY to ARCHIVED.

SyncPoller<PollOperationDetails,ConfigurationSnapshot> beginCreateSnapshot(String snapshotName, ConfigurationSnapshot snapshot, Context context)

Create a ConfigurationSnapshot by providing a snapshot name and a ConfigurationSnapshot.

ConfigurationSetting deleteConfigurationSetting(ConfigurationSetting setting)

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

ConfigurationSetting deleteConfigurationSetting(String key, String label)

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

Response<ConfigurationSetting> deleteConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, Context context)

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

ConfigurationSetting getConfigurationSetting(ConfigurationSetting setting)

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

ConfigurationSetting getConfigurationSetting(String key, String label)

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

ConfigurationSetting getConfigurationSetting(String key, String label, OffsetDateTime acceptDateTime)

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

Response<ConfigurationSetting> 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.

String getEndpoint()

Gets the service endpoint for the Azure App Configuration instance.

ConfigurationSnapshot getSnapshot(String snapshotName)

Get a ConfigurationSnapshot by given the snapshot name.

Response<ConfigurationSnapshot> getSnapshotWithResponse(String snapshotName, List<SnapshotFields> fields, Context context)

Get a ConfigurationSnapshot by given the snapshot name.

PagedIterable<ConfigurationSetting> listConfigurationSettings(SettingSelector selector)

Fetches the configuration settings that match the selector.

PagedIterable<ConfigurationSetting> listConfigurationSettings(SettingSelector selector, Context context)

Fetches the configuration settings that match the selector.

PagedIterable<ConfigurationSetting> listConfigurationSettingsForSnapshot(String snapshotName)

Fetches the configuration settings in a snapshot that matches the snapshotName.

PagedIterable<ConfigurationSetting> listConfigurationSettingsForSnapshot(String snapshotName, List<SettingFields> fields, Context context)

Fetches the configuration settings in a snapshot that matches the snapshotName.

PagedIterable<SettingLabel> listLabels()

Gets all labels

PagedIterable<SettingLabel> listLabels(SettingLabelSelector selector)

Gets a list of labels by given SettingLabelSelector.

PagedIterable<SettingLabel> listLabels(SettingLabelSelector selector, Context context)

Gets a list of labels by given SettingLabelSelector.

PagedIterable<ConfigurationSetting> listRevisions(SettingSelector selector)

Lists chronological/historical representation of ConfigurationSetting resource(s).

PagedIterable<ConfigurationSetting> listRevisions(SettingSelector selector, Context context)

Lists chronological/historical representation of ConfigurationSetting resource(s).

PagedIterable<ConfigurationSnapshot> listSnapshots(SnapshotSelector selector)

List snapshots by given SnapshotSelector.

PagedIterable<ConfigurationSnapshot> listSnapshots(SnapshotSelector selector, Context context)

List snapshots by given SnapshotSelector.

ConfigurationSnapshot recoverSnapshot(String snapshotName)

Update a snapshot status from ARCHIVED to READY.

Response<ConfigurationSnapshot> recoverSnapshotWithResponse(String snapshotName, MatchConditions matchConditions, Context context)

Update a snapshot status from ARCHIVED to READY.

ConfigurationSetting setConfigurationSetting(ConfigurationSetting setting)

Creates or updates a configuration value in the service.

ConfigurationSetting setConfigurationSetting(String key, String label, String value)

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

Response<ConfigurationSetting> setConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, Context context)

Creates or updates a configuration value in the service.

ConfigurationSetting setReadOnly(ConfigurationSetting setting, boolean isReadOnly)

Sets the read-only status for the ConfigurationSetting.

ConfigurationSetting setReadOnly(String key, String label, boolean isReadOnly)

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

Response<ConfigurationSetting> setReadOnlyWithResponse(ConfigurationSetting setting, boolean isReadOnly, Context context)

Sets the read-only status for the ConfigurationSetting.

void updateSyncToken(String token)

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

Methods inherited from java.lang.Object

Method Details

addConfigurationSetting

public ConfigurationSetting 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.

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

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());

Parameters:

setting - The setting to add based on its key and optional label combination.

Returns:

The ConfigurationSetting that was created, or null if a key collision occurs or the key is an invalid value (which will also throw ServiceRequestException described below).

addConfigurationSetting

public ConfigurationSetting 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());

Parameters:

key - The key of the configuration setting to add.
label - The label of the configuration setting to create. If null no label will be used.
value - The value associated with this configuration setting key.

Returns:

The ConfigurationSetting that was created, or null if a key collision occurs or the key is an invalid value (which will also throw ServiceRequestException described below).

addConfigurationSettingWithResponse

public Response 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.

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

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));
 ConfigurationSetting resultSetting = responseResultSetting.getValue();
 System.out.printf("Key: %s, Label: %s, Value: %s", resultSetting.getKey(), resultSetting.getLabel(),
     resultSetting.getValue());

Parameters:

setting - The setting to add based on its key and optional label combination.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A REST response containing the the ConfigurationSetting that was created, or null, if a key collision occurs or the key is an invalid value (which will also throw ServiceRequestException described below).

archiveSnapshot

public ConfigurationSnapshot archiveSnapshot(String snapshotName)

Update a snapshot status from READY to ARCHIVED.

Code Samples

String snapshotName = "{snapshotName}";
 ConfigurationSnapshot archivedSnapshot = client.archiveSnapshot(snapshotName);
 System.out.printf("Archived snapshot name=%s is created at %s, snapshot status is %s.%n",
     archivedSnapshot.getName(), archivedSnapshot.getCreatedAt(), archivedSnapshot.getStatus());

Parameters:

snapshotName - the snapshot name.

Returns:

archiveSnapshotWithResponse

public Response archiveSnapshotWithResponse(String snapshotName, MatchConditions matchConditions, Context context)

Update a snapshot status from READY to ARCHIVED.

To turn on using 'if-match' header, set the second parameter 'ifUnchanged' to true. It used to perform an operation only if the targeted resource's ETag matches the value provided. Otherwise, it will throw an exception '412 Precondition Failed'.

Code Samples

String snapshotName = "{snapshotName}";
 MatchConditions matchConditions = new MatchConditions().setIfMatch("{etag}");
 Context ctx = new Context(key2, value2);

 ConfigurationSnapshot archivedSnapshot = client.archiveSnapshotWithResponse(snapshotName, matchConditions, ctx)
     .getValue();
 System.out.printf("Archived snapshot name=%s is created at %s, snapshot status is %s.%n",
     archivedSnapshot.getName(), archivedSnapshot.getCreatedAt(), archivedSnapshot.getStatus());

Parameters:

snapshotName - the snapshot name.
matchConditions - Specifies HTTP options for conditional requests.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

beginCreateSnapshot

public SyncPoller beginCreateSnapshot(String snapshotName, ConfigurationSnapshot snapshot, Context context)

Create a ConfigurationSnapshot by providing a snapshot name and a ConfigurationSnapshot.

Code Samples

List<ConfigurationSettingsFilter> filters = new ArrayList<>();
 // Key Name also supports RegExp but only support prefix end with "*", such as "k*" and is case-sensitive.
 filters.add(new ConfigurationSettingsFilter("{keyName}"));
 String snapshotName = "{snapshotName}";
 Context ctx = new Context(key2, value2);

 SyncPoller<PollOperationDetails, ConfigurationSnapshot> poller =
     client.beginCreateSnapshot(snapshotName,
         new ConfigurationSnapshot(filters).setRetentionPeriod(Duration.ofHours(1)), ctx);
 poller.setPollInterval(Duration.ofSeconds(10));
 poller.waitForCompletion();
 ConfigurationSnapshot snapshot = poller.getFinalResult();

 System.out.printf("Snapshot name=%s is created at %s%n", snapshot.getName(), snapshot.getCreatedAt());

Parameters:

snapshotName - The name of the ConfigurationSnapshot to create.
snapshot - The snapshot to create.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A SyncPoller<T,U> that polls the creating snapshot operation until it has completed or has failed. The completed operation returns a ConfigurationSnapshot.

deleteConfigurationSetting

public ConfigurationSetting deleteConfigurationSetting(ConfigurationSetting setting)

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

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

Code Samples

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());

Parameters:

setting - The setting to delete based on its key, optional label and optional ETag combination.

Returns:

The deleted ConfigurationSetting or null if it didn't exist. null is also returned if the key is an invalid value (which will also throw ServiceRequestException described below).

deleteConfigurationSetting

public ConfigurationSetting 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", "westUS");
 System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());

Parameters:

key - The key of configuration setting to delete.
label - The label of configuration setting to delete. If null no label will be used.

Returns:

The deleted ConfigurationSetting or null if it didn't exist. null is also returned if the key is an invalid value (which will also throw ServiceRequestException described below).

deleteConfigurationSettingWithResponse

public Response deleteConfigurationSettingWithResponse(ConfigurationSetting setting, boolean ifUnchanged, Context context)

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

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

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());

Parameters:

setting - The setting to delete based on its key, optional label and optional ETag combination.
ifUnchanged - Flag indicating if the setting ETag is used as an IF-MATCH header.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A REST response containing the deleted ConfigurationSetting or null if didn't exist. null is also returned if the getKey() is an invalid value or getETag() is set but does not match the current ETag (which will also throw ServiceRequestException described below).

getConfigurationSetting

public ConfigurationSetting getConfigurationSetting(ConfigurationSetting setting)

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

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

Code Samples

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());

Parameters:

setting - The setting to retrieve.

Returns:

The ConfigurationSetting stored in the service, or null, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below).

getConfigurationSetting

public ConfigurationSetting 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", "westUS");
 System.out.printf("Key: %s, Value: %s", resultNoDateTime.getKey(), resultNoDateTime.getValue());

Parameters:

key - The key of the setting to retrieve.
label - The label of the configuration setting to retrieve. If null no label will be used.

Returns:

The ConfigurationSetting stored in the service, or null, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below).

getConfigurationSetting

public ConfigurationSetting 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", "westUS", null);
 System.out.printf("Key: %s, Value: %s", result.getKey(), result.getValue());

Parameters:

key - The key of the setting to retrieve.
label - The label of the configuration setting to create or update. If null no label will be used.
acceptDateTime - Datetime to access a past state of the configuration setting. If null then the current state of the configuration setting will be returned.

Returns:

The ConfigurationSetting stored in the service, or null, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below).

getConfigurationSettingWithResponse

public Response 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.

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

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());

Parameters:

setting - The setting to retrieve.
acceptDateTime - Datetime to access a past state of the configuration setting. If null then the current state of the configuration setting will be returned.
ifChanged - Flag indicating if the setting ETag is used as an If-None-Match header.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A REST response contains the ConfigurationSetting stored in the service, or null, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below).

getEndpoint

public String getEndpoint()

Gets the service endpoint for the Azure App Configuration instance.

Returns:

the service endpoint for the Azure App Configuration instance.

getSnapshot

public ConfigurationSnapshot getSnapshot(String snapshotName)

Get a ConfigurationSnapshot by given the snapshot name.

Code Samples

String snapshotName = "{snapshotName}";
 ConfigurationSnapshot getSnapshot = client.getSnapshot(snapshotName);
 System.out.printf("Snapshot name=%s is created at %s, snapshot status is %s.%n",
     getSnapshot.getName(), getSnapshot.getCreatedAt(), getSnapshot.getStatus());

Parameters:

snapshotName - the snapshot name.

Returns:

getSnapshotWithResponse

public Response getSnapshotWithResponse(String snapshotName, List fields, Context context)

Get a ConfigurationSnapshot by given the snapshot name.

Code Samples

String snapshotName = "{snapshotName}";
 Context ctx = new Context(key2, value2);
 ConfigurationSnapshot getSnapshot = client.getSnapshotWithResponse(
     snapshotName,
     Arrays.asList(SnapshotFields.NAME, SnapshotFields.CREATED_AT, SnapshotFields.STATUS, SnapshotFields.FILTERS),
     ctx)
     .getValue();
 // Only properties `name`, `createAt`, `status` and `filters` have value, and expect null or
 // empty value other than the `fields` specified in the request.
 System.out.printf("Snapshot name=%s is created at %s, snapshot status is %s.%n",
     getSnapshot.getName(), getSnapshot.getCreatedAt(), getSnapshot.getStatus());
 List<ConfigurationSettingsFilter> filters = getSnapshot.getFilters();
 for (ConfigurationSettingsFilter filter : filters) {
     System.out.printf("Snapshot filter key=%s, label=%s.%n", filter.getKey(), filter.getLabel());
 }

Parameters:

snapshotName - the snapshot name.
fields - Used to select what fields are present in the returned resource(s).
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

listConfigurationSettings

public PagedIterable 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());
 });

Parameters:

selector - Optional. Selector to filter configuration setting results from the service.

Returns:

A PagedIterable<T> of ConfigurationSettings that matches the selector. If no options were provided, the List contains all of the current settings in the service.

listConfigurationSettings

public PagedIterable 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());
 });

Parameters:

selector - Optional. Selector to filter configuration setting results from the service.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A PagedIterable<T> of ConfigurationSettings that matches the selector. If no options were provided, the PagedIterable<T> contains all the current settings in the service.

listConfigurationSettingsForSnapshot

public PagedIterable listConfigurationSettingsForSnapshot(String snapshotName)

Fetches the configuration settings in a snapshot that matches the snapshotName. If snapshotName is null, then all the ConfigurationSetting are fetched with their current values.

Code Samples

String snapshotName = "{snapshotName}";
 configurationClient.listConfigurationSettingsForSnapshot(snapshotName).forEach(setting -> {
     System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue());
 });

Parameters:

snapshotName - Optional. A filter used get ConfigurationSettings for a snapshot. The value should be the name of the snapshot.

Returns:

A PagedIterable<T> of ConfigurationSettings that matches the selector. If no options were provided, the List contains all of the current settings in the service.

listConfigurationSettingsForSnapshot

public PagedIterable listConfigurationSettingsForSnapshot(String snapshotName, List fields, Context context)

Fetches the configuration settings in a snapshot that matches the snapshotName. If snapshotName is null, then all the ConfigurationSetting are fetched with their current values.

Code Samples

String snapshotName = "{snapshotName}";
 List<SettingFields> fields = Arrays.asList(SettingFields.KEY);
 Context ctx = new Context(key2, value2);
 configurationClient.listConfigurationSettingsForSnapshot(snapshotName, fields, ctx)
     .forEach(setting -> System.out.printf("Key: %s, Value: %s", setting.getKey(), setting.getValue()));

Parameters:

snapshotName - Optional. A filter used get ConfigurationSettings for a snapshot. The value should be the name of the snapshot.
fields - Optional. The fields to select for the query response. If none are set, the service will return the ConfigurationSettings with a default set of properties.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A PagedIterable<T> of ConfigurationSettings that matches the selector. If no options were provided, the PagedIterable<T> contains all the current settings in the service.

listLabels

public PagedIterable listLabels()

Gets all labels

Code Samples

client.listLabels()
     .forEach(label -> {
         System.out.println("label name = " + label.getName());
     });

Returns:

a list of labels as paginated response with PagedIterable<T>.

listLabels

public PagedIterable listLabels(SettingLabelSelector selector)

Gets a list of labels by given SettingLabelSelector.

Code Samples

String labelNameFilter = "{labelNamePrefix}*";
 client.listLabels(new SettingLabelSelector().setNameFilter(labelNameFilter))
         .forEach(label -> {
             System.out.println("label name = " + label.getName());
         });

Parameters:

selector - Optional. Selector to filter labels from the service.

Returns:

a list of labels as paginated response with PagedIterable<T>.

listLabels

public PagedIterable listLabels(SettingLabelSelector selector, Context context)

Gets a list of labels by given SettingLabelSelector.

Code Samples

String labelNameFilter = "{labelNamePrefix}*";
 Context ctx = new Context(key2, value2);

 client.listLabels(new SettingLabelSelector().setNameFilter(labelNameFilter), ctx)
         .forEach(label -> {
             System.out.println("label name = " + label.getName());
         });

Parameters:

selector - Optional. Selector to filter labels from the service.
context - The context to associate with this operation.

Returns:

a list of labels as paginated response with PagedIterable<T>.

listRevisions

public PagedIterable 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");
 configurationClient.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);
     });
 });

Parameters:

selector - Optional. Used to filter configuration setting revisions from the service.

Returns:

listRevisions

public PagedIterable 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());
 });

Parameters:

selector - Optional. Used to filter configuration setting revisions from the service.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

listSnapshots

public PagedIterable listSnapshots(SnapshotSelector selector)

List snapshots by given SnapshotSelector.

Code Samples

String snapshotNameFilter = "{snapshotNamePrefix}*";
 client.listSnapshots(new SnapshotSelector().setNameFilter(snapshotNameFilter))
     .forEach(snapshotResult -> {
         System.out.printf("Listed Snapshot name = %s is created at %s, snapshot status is %s.%n",
             snapshotResult.getName(), snapshotResult.getCreatedAt(), snapshotResult.getStatus());
     });

Parameters:

selector - Optional. Used to filter ConfigurationSnapshot from the service.

Returns:

listSnapshots

public PagedIterable listSnapshots(SnapshotSelector selector, Context context)

List snapshots by given SnapshotSelector.

Code Samples

String snapshotNameFilter = "{snapshotNamePrefix}*";
 Context ctx = new Context(key2, value2);

 client.listSnapshots(new SnapshotSelector().setNameFilter(snapshotNameFilter), ctx)
     .forEach(snapshotResult -> {
         System.out.printf("Listed Snapshot name = %s is created at %s, snapshot status is %s.%n",
             snapshotResult.getName(), snapshotResult.getCreatedAt(), snapshotResult.getStatus());
     });

Parameters:

selector - Optional. Used to filter ConfigurationSnapshot from the service.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

recoverSnapshot

public ConfigurationSnapshot recoverSnapshot(String snapshotName)

Update a snapshot status from ARCHIVED to READY.

Code Samples

String snapshotName = "{snapshotName}";
 ConfigurationSnapshot recoveredSnapshot = client.recoverSnapshot(snapshotName);
 System.out.printf("Recovered snapshot name=%s is created at %s, snapshot status is %s.%n",
     recoveredSnapshot.getName(), recoveredSnapshot.getCreatedAt(), recoveredSnapshot.getStatus());

Parameters:

snapshotName - the snapshot name.

Returns:

recoverSnapshotWithResponse

public Response recoverSnapshotWithResponse(String snapshotName, MatchConditions matchConditions, Context context)

Update a snapshot status from ARCHIVED to READY.

To turn on using 'if-match' header, set the second parameter 'ifUnchanged' to true. It used to perform an operation only if the targeted resource's ETag matches the value provided. Otherwise, it will throw an exception '412 Precondition Failed'.

Code Samples

String snapshotName = "{snapshotName}";
 MatchConditions matchConditions = new MatchConditions().setIfMatch("{etag}");
 Context ctx = new Context(key2, value2);

 ConfigurationSnapshot recoveredSnapshot = client.recoverSnapshotWithResponse(snapshotName, matchConditions, ctx)
     .getValue();
 System.out.printf("Recovered snapshot name=%s is created at %s, snapshot status is %s.%n",
     recoveredSnapshot.getName(), recoveredSnapshot.getCreatedAt(), recoveredSnapshot.getStatus());

Parameters:

snapshotName - the snapshot name.
matchConditions - Specifies HTTP options for conditional requests.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

setConfigurationSetting

public ConfigurationSetting setConfigurationSetting(ConfigurationSetting setting)

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

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

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());

Parameters:

setting - The setting to create or update based on its key, optional label and optional ETag combination.

Returns:

The ConfigurationSetting that was created or updated, or null if the key is an invalid value (which will also throw ServiceRequestException described below).

setConfigurationSetting

public ConfigurationSetting 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());

Parameters:

key - The key of the configuration setting to create or update.
label - The label of the configuration setting to create or update. If null no label will be used.
value - The value of this configuration setting.

Returns:

The ConfigurationSetting that was created or updated, or null if the key is an invalid value (which will also throw ServiceRequestException described below).

setConfigurationSettingWithResponse

public Response 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.

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

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));
 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));
 ConfigurationSetting updatedSetting = responseSetting.getValue();
 System.out.printf("Key: %s, Value: %s", updatedSetting.getKey(), updatedSetting.getValue());

Parameters:

setting - The setting to create or update based on its key, optional label and optional ETag combination.
ifUnchanged - A boolean indicates if setting ETag is used as an IF-MATCH header.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A REST response contains the ConfigurationSetting that was created or updated, or null, if the configuration value does not exist or the key is an invalid value (which will also throw ServiceRequestException described below).

setReadOnly

public ConfigurationSetting setReadOnly(ConfigurationSetting setting, boolean isReadOnly)

Sets the read-only status for the ConfigurationSetting.

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

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());

Parameters:

setting - The configuration setting to set to read-only or not read-only based on the isReadOnly.
isReadOnly - Flag used to set the read-only status of the configuration. true will put the configuration into a read-only state, false will clear the state.

Returns:

The ConfigurationSetting that is read-only, or null is also returned if a key collision occurs or the key is an invalid value (which will also throw HttpResponseException described below).

setReadOnly

public ConfigurationSetting 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());

Parameters:

key - The key of configuration setting to set to read-only or not read-only based on the isReadOnly.
label - The label of configuration setting to set to read-only or not read-only based on the isReadOnly value, or optionally. If null no label will be used.
isReadOnly - Flag used to set the read-only status of the configuration. true will put the configuration into a read-only state, false will clear the state.

Returns:

The ConfigurationSetting that is read-only, or null is also returned if a key collision occurs or the key is an invalid value (which will also throw HttpResponseException described below).

setReadOnlyWithResponse

public Response setReadOnlyWithResponse(ConfigurationSetting setting, boolean isReadOnly, Context context)

Sets the read-only status for the ConfigurationSetting.

For more configuration setting types, see FeatureFlagConfigurationSetting and SecretReferenceConfigurationSetting.

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());

Parameters:

setting - The configuration setting to set to read-only or not read-only based on the isReadOnly.
isReadOnly - Flag used to set the read-only status of the configuration. true will put the configuration into a read-only state, false will clear the state.
context - Additional context that is passed through the Http pipeline during the service call.

Returns:

A REST response containing the read-only or not read-only ConfigurationSetting if isReadOnly is true or null, or false respectively. Or return null if the setting didn't exist. null is also returned if the getKey() is an invalid value. (which will also throw HttpResponseException described below).

updateSyncToken

public void updateSyncToken(String token)

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

Parameters:

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

Applies to