ConfigurationClient Class
- java.
lang. Object - com.
azure. data. appconfiguration. ConfigurationClient
- com.
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.
- Connection string, see connectionString(String connectionString).
- 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
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:
Returns:
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:
null
no label will be used.
Returns:
null
if a key collision occurs or the key
is an invalid value (which will also throw ServiceRequestException described below).addConfigurationSettingWithResponse
public Response
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:
Returns:
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:
Returns:
archiveSnapshotWithResponse
public Response
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:
Returns:
beginCreateSnapshot
public SyncPoller
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:
Returns:
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:
Returns:
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:
null
no label will be used.
Returns:
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
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
ETag is used as an
IF-MATCH header.
Returns:
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:
Returns:
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:
null
no label will be used.
Returns:
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:
null
no label will be used.
null
then the current state of the configuration setting will be returned.
Returns:
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
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:
null
then the current state of the configuration setting will be returned.
setting
ETag is used as an
If-None-Match header.
Returns:
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:
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:
Returns:
getSnapshotWithResponse
public Response
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:
Returns:
listConfigurationSettings
public PagedIterable
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:
Returns:
selector
. If no options were
provided, the List contains all of the current settings in the service.listConfigurationSettings
public PagedIterable
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:
Returns:
selector
. If no options were
provided, the PagedIterable<T> contains all the current settings in the service.listConfigurationSettingsForSnapshot
public PagedIterable
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:
Returns:
selector
. If no options were
provided, the List contains all of the current settings in the service.listConfigurationSettingsForSnapshot
public PagedIterable
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:
Returns:
selector
. If no options were
provided, the PagedIterable<T> contains all the current settings in the service.listLabels
public PagedIterable
Gets all labels
Code Samples
client.listLabels()
.forEach(label -> {
System.out.println("label name = " + label.getName());
});
Returns:
listLabels
public PagedIterable
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:
Returns:
listLabels
public PagedIterable
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:
Returns:
listRevisions
public PagedIterable
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:
Returns:
listRevisions
public PagedIterable
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:
Returns:
listSnapshots
public PagedIterable
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:
Returns:
listSnapshots
public PagedIterable
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:
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:
Returns:
recoverSnapshotWithResponse
public Response
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:
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:
Returns:
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:
null
no label will be used.
Returns:
null
if the key is an invalid
value (which will also throw ServiceRequestException described below).setConfigurationSettingWithResponse
public Response
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
ETag is used as an
IF-MATCH header.
Returns:
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:
isReadOnly
.
true
will put the
configuration into a read-only state, false
will clear the state.
Returns:
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:
isReadOnly
.
isReadOnly
value, or optionally. If null
no label will be used.
true
will put the
configuration into a read-only state, false
will clear the state.
Returns:
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
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:
isReadOnly
.
true
will put the
configuration into a read-only state, false
will clear the state.
Returns:
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:
Applies to
Azure SDK for Java