Dynamic Request Options
Dynamic Request Options
This is a feature for configuring some of the configurations in the request options dynamically. Customers should be able to change the request options of their application without restarting it. Below is a code snippet of how the dynamic request options could be used. Currently this is just a poc with the create item operation.
CosmosAsyncClient cosmosAsyncClient = new CosmosClientBuilder()
.endpoint("something")
.key("secret")
.setRequestOptionsTransformer((requestOptionsWrapper) -> {
// Read from config file
Properties prop = new Properties();
String fileName = "app.config";
try (FileInputStream fis = new FileInputStream(fileName)) {
prop.load(fis);
} catch (FileNotFoundException ex) {
// Handle file not found exception
} catch (IOException ex) {
// Handle other I/O exceptions
}
// ----------------------------------------------------------------------------
// Figure out Operation
CosmosDiagnosticsContext cosmosDiagnosticsContext = requestOptionsWrapper.getCosmosDiagnosticsContext();
String operationType = cosmosDiagnosticsContext.getOperationType();
String resourceType = cosmosDiagnosticsContext.getResourceType();
if (operationType.equals("Create") && resourceType.equals("Document")) {
// change request options for createItem --------------------------------------------------------------
CosmosCommonRequestOptions cosmosCommonRequestOptions = new CosmosCommonRequestOptions();
cosmosCommonRequestOptions.setCosmosEndToEndLatencyPolicyConfig(new CosmosEndToEndOperationLatencyPolicyConfig(true,
Duration.ofSeconds(Long.parseLong(prop.getProperty("timeout.seconds"))),
new ThresholdBasedAvailabilityStrategy()));
requestOptionsWrapper.applyOverride(cosmosCommonRequestOptions);
}
})
.buildAsyncClient();
@tvaron3 / @FabianMeiswinkel / @xinlian12 / @jeet1995 / @TheovanKraay / @trande4884 we need to think about spring-data-cosmos SDK use case as well here. Because we are not going to expose requestOptions to spring-data-cosmos or kafka connector for that matter. So we should just make sure this extension approach works for all the connectors.
@tvaron3 / @FabianMeiswinkel / @xinlian12 / @jeet1995 / @TheovanKraay / @trande4884 we need to think about spring-data-cosmos SDK use case as well here. Because we are not going to expose
requestOptionsto spring-data-cosmos or kafka connector for that matter. So we should just make sure this extension approach works for all the connectors.
For spring I can check functionality once this is released!
/azp run java - cosmos - tests
Azure Pipelines successfully started running 1 pipeline(s).
/azp run java - cosmos - tests
Azure Pipelines successfully started running 1 pipeline(s).
/azp run java - cosmos - tests
Azure Pipelines successfully started running 1 pipeline(s).
/azp run java - cosmos - tests
Azure Pipelines successfully started running 1 pipeline(s).
/azp run java - cosmos - tests
Azure Pipelines successfully started running 1 pipeline(s).
/azp run java - cosmos - tests
Azure Pipelines successfully started running 1 pipeline(s).
/azp run java - cosmos - tests
Azure Pipelines successfully started running 1 pipeline(s).