use of com.azure.cosmos.CosmosClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleDocumentationSnippets method PerformanceTipsJavaSDKv4ClientSync.
/**
* 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 PerformanceTipsJavaSDKv4ClientSync() {
String HOSTNAME = "";
String MASTERKEY = "";
// Arbitrary
ConsistencyLevel CONSISTENCY = ConsistencyLevel.EVENTUAL;
// <PerformanceClientSync>
CosmosClient client = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).buildClient();
// </PerformanceClientSync>
}
use of com.azure.cosmos.CosmosClient in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleDocumentationSnippets method PerformanceTipsJavaSDKv4ConnectionModeSync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - sync Connection Mode
*/
/**
* Performance tips - sync Connection Mode
*/
public static void PerformanceTipsJavaSDKv4ConnectionModeSync() {
String HOSTNAME = "";
String MASTERKEY = "";
// Arbitrary
ConsistencyLevel CONSISTENCY = ConsistencyLevel.EVENTUAL;
// <PerformanceClientConnectionModeSync>
/* Direct mode, default settings */
CosmosClient clientDirectDefault = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).directMode().buildClient();
/* Direct mode, custom settings */
DirectConnectionConfig directConnectionConfig = DirectConnectionConfig.getDefaultConfig();
// Example config, do not use these settings as defaults
directConnectionConfig.setMaxConnectionsPerEndpoint(120);
directConnectionConfig.setIdleConnectionTimeout(Duration.ofMillis(100));
CosmosClient clientDirectCustom = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).directMode(directConnectionConfig).buildClient();
/* Gateway mode, default settings */
CosmosClient clientGatewayDefault = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).gatewayMode().buildClient();
/* Gateway mode, custom settings */
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);
CosmosClient clientGatewayCustom = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).gatewayMode(gatewayConnectionConfig).buildClient();
/* No connection mode, defaults to Direct mode with default settings */
CosmosClient clientDefault = new CosmosClientBuilder().endpoint(HOSTNAME).key(MASTERKEY).consistencyLevel(CONSISTENCY).buildClient();
// </PerformanceClientConnectionModeSync>
}
use of com.azure.cosmos.CosmosClient in project DataSpaceConnector by eclipse-dataspaceconnector.
the class CosmosDbApiImpl method getContainer.
private static CosmosContainer getContainer(Vault vault, AbstractCosmosConfig config) {
CosmosClient client = createClient(vault, config.getAccountName(), Collections.singletonList(config.getPreferredRegion()));
CosmosDatabase database = getDatabase(client, config.getDbName());
if (database.readAllContainers().stream().noneMatch(sp -> sp.getId().equals(config.getContainerName()))) {
throw new EdcException("No CosmosDB container named '" + config.getContainerName() + "' was found in account '" + config.getAccountName() + "'. Please create one, preferably using terraform.");
}
return database.getContainer(config.getContainerName());
}
Aggregations