.Session);
try {
// Create the lease container if it does not exist
createLeaseContainerIfNotExists(documentClient, DATABASE_ID, LEASE_CONTAINER_ID);
scss
Copy code
// Define the ChangeFeedOptions ChangeFeedOptions changeFeedOptions = new ChangeFeedOptions(); changeFeedOptions.setStartFromBeginning(true); // Define the ChangeFeedProcessor options ChangeFeedProcessorOptions changeFeedProcessorOptions = new ChangeFeedProcessorOptions(); changeFeedProcessorOptions.setLeasePrefix("myChangeFeed"); // Define the ChangeFeedProcessor ChangeFeedProcessor changeFeedProcessor = new ChangeFeedProcessorBuilder() .withDocumentClient(documentClient) .withFeedCollection(DATABASE_ID, CONTAINER_ID) .withLeaseCollection(DATABASE_ID, LEASE_CONTAINER_ID) .withProcessorOptions(changeFeedProcessorOptions) .withHandleChanges(ChangeFeedProcessorExample::processChanges) .build(); // Start the ChangeFeedProcessor changeFeedProcessor.start(); } catch (DocumentClientException e) { System.err.println("An error occurred while processing the Change Feed: " + e); } } private static void processChanges(List<Document> docs, CancellationToken cancellationToken) { for (Document doc : docs) { System.out.println("Change: " + doc.toJson()); } } private static void createLeaseContainerIfNotExists(DocumentClient documentClient, String databaseId, String containerId) throws DocumentClientException { String collectionLink = String.format("/dbs/%s/colls/%s", databaseId, containerId); try { documentClient.readContainer(collectionLink, new FeedOptions()).getResource(); } catch (DocumentClientException e) { if (e.getStatusCode() == 404) { DocumentCollection collectionDefinition = new DocumentCollection(); collectionDefinition.setId(containerId); RequestOptions requestOptions = new RequestOptions(); requestOptions.setOfferThroughput(400); documentClient.createContainer(databaseId, collectionDefinition, requestOptions); } else { throw e; } } }
}
spam lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor creativity violence