use of com.azure.cosmos.CosmosAsyncContainer in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method PerformanceTipsJavaSDKv4RequestChargeSpecAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - get request charge
*/
/**
* Performance tips - get request charge
*/
public static void PerformanceTipsJavaSDKv4RequestChargeSpecAsync() {
CosmosAsyncContainer asyncContainer = null;
CustomPOJO item = null;
String pk = "pk_value";
// <PerformanceRequestChargeAsync>
CosmosItemResponse<CustomPOJO> response = asyncContainer.createItem(item).block();
response.getRequestCharge();
// </PerformanceRequestChargeAsync>
}
use of com.azure.cosmos.CosmosAsyncContainer in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method MigrateJavaSDKv4ContainerTTLAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/migrate-java-v4-sdk
* Container TTL
*/
/**
* Container TTL
*/
public static void MigrateJavaSDKv4ContainerTTLAsync() {
String hostName = "hostname";
String partition_key = "/pk";
CosmosAsyncDatabase database = null;
// <MigrateContainerTTLAsync>
CosmosAsyncContainer container;
// Create a new container with TTL enabled with default expiration value
CosmosContainerProperties containerProperties = new CosmosContainerProperties("myContainer", "/myPartitionKey");
containerProperties.setDefaultTimeToLiveInSeconds(90 * 60 * 60 * 24);
ThroughputProperties throughputProperties = ThroughputProperties.createManualThroughput(400);
database.createContainerIfNotExists(containerProperties, throughputProperties).block();
container = database.getContainer("myContainer");
// </MigrateContainerTTLAsync>
}
use of com.azure.cosmos.CosmosAsyncContainer in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method TroubleshootingGuideJavaSDKv4NeedsSchedulerAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/troubleshoot-java-sdk-v4-sql
* Troubleshooting guide - needs scheduler
* Async only
*/
/**
* Troubleshooting guide - needs scheduler
*/
public static void TroubleshootingGuideJavaSDKv4NeedsSchedulerAsync() {
CosmosAsyncContainer container = null;
CustomPOJO item = null;
// <TroubleshootNeedsSchedulerAsync>
// Bad code with read timeout exception
int requestTimeoutInSeconds = 10;
/* ... */
AtomicInteger failureCount = new AtomicInteger();
// Max number of concurrent item inserts is # CPU cores + 1
Flux<Family> familyPub = Flux.just(Families.getAndersenFamilyItem(), Families.getAndersenFamilyItem(), Families.getJohnsonFamilyItem());
familyPub.flatMap(family -> {
return container.createItem(family);
}).flatMap(r -> {
try {
// Time-consuming work is, for example,
// writing to a file, computationally heavy work, or just sleep.
// Basically, it's anything that takes more than a few milliseconds.
// Doing such operations on the IO Netty thread
// without a proper scheduler will cause problems.
// The subscriber will get a ReadTimeoutException failure.
TimeUnit.SECONDS.sleep(2 * requestTimeoutInSeconds);
} catch (Exception e) {
}
return Mono.empty();
}).doOnError(Exception.class, exception -> {
failureCount.incrementAndGet();
}).blockLast();
assert (failureCount.get() > 0);
// </TroubleshootNeedsSchedulerAsync>
}
use of com.azure.cosmos.CosmosAsyncContainer in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method PerformanceTipsJavaSDKv4NoPKSpecAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - not specifying partition key in point-writes
*/
/**
* Performance tips - not specifying partition key in point-writes
*/
public static void PerformanceTipsJavaSDKv4NoPKSpecAsync() {
CosmosAsyncContainer asyncContainer = null;
CustomPOJO item = null;
String pk = "pk_value";
// <PerformanceNoPKAsync>
asyncContainer.createItem(item, new PartitionKey(pk), new CosmosItemRequestOptions()).block();
// </PerformanceNoPKAsync>
}
use of com.azure.cosmos.CosmosAsyncContainer in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method PerformanceTipsJavaSDKv4AddPKSpecAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - add partition key in point-writes
*/
/**
* Performance tips - add partition key in point-writes
*/
public static void PerformanceTipsJavaSDKv4AddPKSpecAsync() {
CosmosAsyncContainer asyncContainer = null;
CustomPOJO item = null;
// <PerformanceAddPKAsync>
asyncContainer.createItem(item).block();
// </PerformanceAddPKAsync>
}
Aggregations