use of com.azure.cosmos.models.CosmosItemResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleIndexManagementAsync method readItems.
private void readItems(Flux<Family> familiesToCreate) {
// Using partition key for point read scenarios.
// This will help fast look up of items because of partition key
// <ReadItem>
final CountDownLatch completionLatch = new CountDownLatch(1);
familiesToCreate.flatMap(family -> {
Mono<CosmosItemResponse<Family>> asyncItemResponseMono = container.readItem(family.getId(), new PartitionKey(family.getLastName()), Family.class);
return asyncItemResponseMono;
}).subscribe(itemResponse -> {
double requestCharge = itemResponse.getRequestCharge();
Duration requestLatency = itemResponse.getDuration();
logger.info(String.format("Item successfully read with id %s with a charge of %.2f and within duration %s", itemResponse.getItem().getId(), requestCharge, requestLatency));
}, err -> {
if (err instanceof CosmosException) {
// Client-specific errors
CosmosException cerr = (CosmosException) err;
cerr.printStackTrace();
logger.info(String.format("Read Item failed with %s\n", cerr));
} else {
// General errors
err.printStackTrace();
}
completionLatch.countDown();
}, () -> {
completionLatch.countDown();
});
try {
completionLatch.await();
} catch (InterruptedException err) {
throw new AssertionError("Unexpected Interruption", err);
}
// </ReadItem>
}
use of com.azure.cosmos.models.CosmosItemResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method PerformanceTipsJavaSDKv4NeedsSchedulerAsync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - needs scheduler
* Async only
*/
/**
* Performance tips - needs scheduler
*/
public static void PerformanceTipsJavaSDKv4NeedsSchedulerAsync() {
CosmosAsyncContainer asyncContainer = null;
CustomPOJO item = null;
// <PerformanceNeedsSchedulerAsync>
Mono<CosmosItemResponse<CustomPOJO>> createItemPub = asyncContainer.createItem(item);
createItemPub.subscribe(itemResponse -> {
// this is executed on eventloop IO netty thread.
// the eventloop thread is shared and is meant to return back quickly.
//
// DON'T do this on eventloop IO netty thread.
veryCpuIntensiveWork();
});
// </PerformanceNeedsSchedulerAsync>
}
use of com.azure.cosmos.models.CosmosItemResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SalesOrder method PerformanceTipsJavaSDKv4AddSchedulerSync.
/**
* https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
* Performance tips - add scheduler
* Async only
*/
/**
* Performance tips - add scheduler
*/
public static void PerformanceTipsJavaSDKv4AddSchedulerSync() {
CosmosAsyncContainer asyncContainer = null;
CustomPOJO item = null;
// <PerformanceAddSchedulerAsync>
Mono<CosmosItemResponse<CustomPOJO>> createItemPub = asyncContainer.createItem(item);
createItemPub.subscribeOn(Schedulers.elastic()).subscribe(itemResponse -> {
// this is executed on eventloop IO netty thread.
// the eventloop thread is shared and is meant to return back quickly.
//
// DON'T do this on eventloop IO netty thread.
veryCpuIntensiveWork();
});
// </PerformanceAddSchedulerAsync>
}
use of com.azure.cosmos.models.CosmosItemResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStartAsync method replaceDocument.
private void replaceDocument() throws Exception {
logger.info("Replace document : {}", documentId);
// Replace existing document with new modified document
Family family = new Family();
family.setLastName(documentLastName);
family.setId(documentId);
// Document modification
family.setDistrict("Columbia");
Mono<CosmosItemResponse<Family>> itemResponseMono = container.replaceItem(family, family.getId(), new PartitionKey(family.getLastName()), new CosmosItemRequestOptions());
CosmosItemResponse<Family> itemResponse = itemResponseMono.block();
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Replace item diagnostics : {}", diagnostics);
logger.info("Request charge of replace operation: {} RU", itemResponse.getRequestCharge());
logger.info("Done.");
}
use of com.azure.cosmos.models.CosmosItemResponse in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class CosmosDiagnosticsQuickStartAsync method upsertDocument.
private void upsertDocument() throws Exception {
logger.info("Replace document : {}", documentId);
// Replace existing document with new modified document (contingent on modification).
Family family = new Family();
family.setLastName(documentLastName);
family.setId(documentId);
// Document modification
family.setDistrict("Columbia");
Mono<CosmosItemResponse<Family>> itemResponseMono = container.upsertItem(family, new CosmosItemRequestOptions());
CosmosItemResponse<Family> itemResponse = itemResponseMono.block();
CosmosDiagnostics diagnostics = itemResponse.getDiagnostics();
logger.info("Upsert item diagnostics : {}", diagnostics);
logger.info("Done.");
}
Aggregations