Search in sources :

Example 1 with CustomPOJO2

use of com.azure.cosmos.examples.common.CustomPOJO2 in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SampleChangeFeedProcessor method createNewDocumentsCustomPOJO.

public static void createNewDocumentsCustomPOJO(CosmosAsyncContainer containerClient, int count, Duration delay) {
    String suffix = RandomStringUtils.randomAlphabetic(10);
    for (int i = 0; i <= count; i++) {
        CustomPOJO2 document = new CustomPOJO2();
        document.setId(String.format("0%d-%s", i, suffix));
        // This is a very simple example, so we'll just have a partition key (/pk) field that we set equal to id
        document.setPk(document.getId());
        containerClient.createItem(document).subscribe(doc -> {
            logger.info("---->DOCUMENT WRITE: " + doc);
        });
        long remainingWork = delay.toMillis();
        try {
            while (remainingWork > 0) {
                Thread.sleep(100);
                remainingWork -= 100;
            }
        } catch (InterruptedException iex) {
            // exception caught
            break;
        }
    }
}
Also used : CustomPOJO2(com.azure.cosmos.examples.common.CustomPOJO2)

Aggregations

CustomPOJO2 (com.azure.cosmos.examples.common.CustomPOJO2)1