azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

Dynamic Request Options

Open tvaron3 opened this issue 1 year ago • 2 comments

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 avatar May 07 '24 00:05 tvaron3

@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.

kushagraThapar avatar May 08 '24 17:05 kushagraThapar

@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.

For spring I can check functionality once this is released!

trande4884 avatar May 09 '24 18:05 trande4884

/azp run java - cosmos - tests

tvaron3 avatar Jun 13 '24 00:06 tvaron3

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 13 '24 00:06 azure-pipelines[bot]

/azp run java - cosmos - tests

FabianMeiswinkel avatar Jun 21 '24 00:06 FabianMeiswinkel

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 21 '24 00:06 azure-pipelines[bot]

/azp run java - cosmos - tests

tvaron3 avatar Jun 21 '24 21:06 tvaron3

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 21 '24 21:06 azure-pipelines[bot]

/azp run java - cosmos - tests

tvaron3 avatar Jun 26 '24 15:06 tvaron3

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 26 '24 15:06 azure-pipelines[bot]

/azp run java - cosmos - tests

tvaron3 avatar Jun 26 '24 17:06 tvaron3

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 26 '24 17:06 azure-pipelines[bot]

/azp run java - cosmos - tests

tvaron3 avatar Jun 27 '24 15:06 tvaron3

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 27 '24 15:06 azure-pipelines[bot]

/azp run java - cosmos - tests

tvaron3 avatar Jun 28 '24 19:06 tvaron3

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Jun 28 '24 19:06 azure-pipelines[bot]