Search in sources :

Example 6 with CosmosAsyncClient

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>
}
Also used : CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) CosmosAsyncClient(com.azure.cosmos.CosmosAsyncClient) ArrayList(java.util.ArrayList)

Example 7 with CosmosAsyncClient

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>
}
Also used : CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) CosmosAsyncClient(com.azure.cosmos.CosmosAsyncClient)

Example 8 with CosmosAsyncClient

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>
}
Also used : ConsistencyLevel(com.azure.cosmos.ConsistencyLevel) CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) CosmosAsyncClient(com.azure.cosmos.CosmosAsyncClient)

Example 9 with CosmosAsyncClient

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>
}
Also used : ConsistencyLevel(com.azure.cosmos.ConsistencyLevel) CosmosClientBuilder(com.azure.cosmos.CosmosClientBuilder) DirectConnectionConfig(com.azure.cosmos.DirectConnectionConfig) ProxyOptions(com.azure.core.http.ProxyOptions) CosmosAsyncClient(com.azure.cosmos.CosmosAsyncClient) GatewayConnectionConfig(com.azure.cosmos.GatewayConnectionConfig)

Aggregations

CosmosAsyncClient (com.azure.cosmos.CosmosAsyncClient)9 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)9 ConsistencyLevel (com.azure.cosmos.ConsistencyLevel)5 ProxyOptions (com.azure.core.http.ProxyOptions)3 DirectConnectionConfig (com.azure.cosmos.DirectConnectionConfig)3 GatewayConnectionConfig (com.azure.cosmos.GatewayConnectionConfig)3 ArrayList (java.util.ArrayList)3 ChangeFeedProcessor (com.azure.cosmos.ChangeFeedProcessor)2 ChangeFeedProcessorBuilder (com.azure.cosmos.ChangeFeedProcessorBuilder)2 CosmosAsyncContainer (com.azure.cosmos.CosmosAsyncContainer)2 CosmosAsyncDatabase (com.azure.cosmos.CosmosAsyncDatabase)2 CosmosContainerProperties (com.azure.cosmos.models.CosmosContainerProperties)2 CosmosContainerResponse (com.azure.cosmos.models.CosmosContainerResponse)2 CosmosDatabaseResponse (com.azure.cosmos.models.CosmosDatabaseResponse)2 ThroughputProperties (com.azure.cosmos.models.ThroughputProperties)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Duration (java.time.Duration)2 List (java.util.List)2