use of com.azure.cosmos.examples.common.Families in project azure-cosmos-java-sql-api-samples by Azure-Samples.
the class SampleIndexManagementAsync method createFamilies.
private void createFamilies(Flux<Family> families) throws Exception {
// <CreateItem>
final CountDownLatch completionLatch = new CountDownLatch(1);
// Combine multiple item inserts, associated success println's, and a final aggregate stats println into one Reactive stream.
families.flatMap(family -> {
return container.createItem(family);
}).flatMap(itemResponse -> {
logger.info(String.format("Created item with request charge of %.2f within" + " duration %s", itemResponse.getRequestCharge(), itemResponse.getDuration()));
logger.info(String.format("Item ID: %s\n", itemResponse.getItem().getId()));
return Mono.just(itemResponse.getRequestCharge());
}).reduce(0.0, (charge_n, charge_nplus1) -> charge_n + charge_nplus1).subscribe(charge -> {
logger.info(String.format("Created items with total request charge of %.2f\n", charge));
}, 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);
}
// </CreateItem>
}
Aggregations