use of com.azure.cosmos.CosmosAsyncClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method ConfigureMultimasterInYourApplicationsThatUseComosDBAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-multi-master
* Multi-master tutorial
*/
/**
* Enable multi-master from client
*/
public static void ConfigureMultimasterInYourApplicationsThatUseComosDBAsync() {
String MASTER_KEY = "";
String HOST = "";
String region = "West US 2";
// <ConfigureMultimasterAsync>
ArrayList<String> preferredRegions = new ArrayList<String>();
preferredRegions.add(region);
CosmosAsyncClient client = new CosmosClientBuilder().endpoint(HOST).key(MASTER_KEY).multipleWriteRegionsEnabled(true).preferredRegions(preferredRegions).buildAsyncClient();
// </ConfigureMultimasterAsync>
}
use of com.azure.cosmos.CosmosAsyncClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method ManageConsistencyLevelsInAzureCosmosDBAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-manage-consistency
* Manage consistency
*/
/**
* Managed consistency from client
*/
public static void ManageConsistencyLevelsInAzureCosmosDBAsync() {
String MASTER_KEY = "";
String HOST = "";
// <ManageConsistencyAsync>
CosmosAsyncClient client = new CosmosClientBuilder().endpoint(HOST).key(MASTER_KEY).consistencyLevel(ConsistencyLevel.EVENTUAL).buildAsyncClient();
// </ManageConsistencyAsync>
}
use of com.azure.cosmos.CosmosAsyncClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method PerformanceTipsJavaSDKv4ClientAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - needs scheduler
*/
/**
* Performance tips - needs scheduler
*/
public static void PerformanceTipsJavaSDKv4ClientAsync() {
String HOSTNAME = "";
String MASTERKEY = "";
// Arbitrary
ConsistencyLevel CONSISTENCY = ConsistencyLevel.EVENTUAL;
// <PerformanceClientAsync>
CosmosAsyncClient client = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).buildAsyncClient();
// </PerformanceClientAsync>
}
use of com.azure.cosmos.CosmosAsyncClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method PerformanceTipsJavaSDKv4CDirectOverrideAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - Direct data plane, Gateway control plane
*/
/**
* Performance tips - Direct data plane, Gateway control plane
*/
public static void PerformanceTipsJavaSDKv4CDirectOverrideAsync() {
String HOSTNAME = "";
String MASTERKEY = "";
// Arbitrary
ConsistencyLevel CONSISTENCY = ConsistencyLevel.EVENTUAL;
// <PerformanceClientDirectOverrideAsync>
/* Independent customization of Direct mode data plane and Gateway mode control plane */
DirectConnectionConfig directConnectionConfig = DirectConnectionConfig.getDefaultConfig();
// Example config, do not use these settings as defaults
directConnectionConfig.setMaxConnectionsPerEndpoint(120);
directConnectionConfig.setIdleConnectionTimeout(Duration.ofMillis(100));
GatewayConnectionConfig gatewayConnectionConfig = GatewayConnectionConfig.getDefaultConfig();
// Example config, do not use these settings as defaults
gatewayConnectionConfig.setProxy(new ProxyOptions(ProxyOptions.Type.HTTP, InetSocketAddress.createUnresolved("your.proxy.addr", 80)));
gatewayConnectionConfig.setMaxConnectionPoolSize(150);
CosmosAsyncClient clientDirectCustom = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).directMode(directConnectionConfig, gatewayConnectionConfig).buildAsyncClient();
// </PerformanceClientDirectOverrideAsync>
}
Aggregations