Package com.azure.cosmos
Class ChangeFeedProcessorBuilder
java.lang.Object
com.azure.cosmos.ChangeFeedProcessorBuilder
Helper class to build a
ChangeFeedProcessor instance.
Below is an example of building ChangeFeedProcessor for LatestVersion mode.
ChangeFeedProcessor changeFeedProcessor = new ChangeFeedProcessorBuilder()
.hostName(hostName)
.feedContainer(feedContainer)
.leaseContainer(leaseContainer)
.handleChanges(docs -> {
for (JsonNode item : docs) {
// Implementation for handling and processing of each JsonNode item goes here
}
})
.buildChangeFeedProcessor();
Below is an example of building ChangeFeedProcessor for AllVersionsAndDeletes mode.
ChangeFeedProcessor changeFeedProcessor = new ChangeFeedProcessorBuilder()
.hostName(hostName)
.feedContainer(feedContainer)
.leaseContainer(leaseContainer)
.handleAllVersionsAndDeletesChanges(docs -> {
for (ChangeFeedProcessorItem item : docs) {
// Implementation for handling and processing of each ChangeFeedProcessorItem item goes here
}
})
.buildChangeFeedProcessor();
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new Cosmos a new ChangeFeedProcessor builder. -
Method Summary
Modifier and TypeMethodDescriptionBuilds a new instance of theChangeFeedProcessorwith the specified configuration.feedContainer(CosmosAsyncContainer feedContainer) Sets and existingCosmosAsyncContainerto be used to read from the monitored container.Sets a consumer function which will be called to process changes for AllVersionsAndDeletes change feed mode.handleChanges(Consumer<List<JsonNode>> consumer) Sets a consumer function which will be called to process changes for LatestVersion change feed mode.Sets the host name.leaseContainer(CosmosAsyncContainer leaseContainer) Sets an existingCosmosAsyncContainerto be used to read from the leases container.options(ChangeFeedProcessorOptions changeFeedProcessorOptions) Sets theChangeFeedProcessorOptionsto be used.
-
Constructor Details
-
ChangeFeedProcessorBuilder
public ChangeFeedProcessorBuilder()Instantiates a new Cosmos a new ChangeFeedProcessor builder.
-
-
Method Details
-
hostName
Sets the host name.- Parameters:
hostName- the name to be used for the host. When using multiple hosts, each host must have a unique name.- Returns:
- current Builder.
-
feedContainer
Sets and existingCosmosAsyncContainerto be used to read from the monitored container.- Parameters:
feedContainer- the instance ofCosmosAsyncContainerto be used.- Returns:
- current Builder.
-
leaseContainer
Sets an existingCosmosAsyncContainerto be used to read from the leases container.- Parameters:
leaseContainer- the instance ofCosmosAsyncContainerto use.- Returns:
- current Builder.
-
handleChanges
Sets a consumer function which will be called to process changes for LatestVersion change feed mode..handleChanges(docs -> { for (JsonNode item : docs) { // Implementation for handling and processing of each JsonNode item goes here } })- Parameters:
consumer- theConsumerto call for handling the feeds.- Returns:
- current Builder.
-
handleAllVersionsAndDeletesChanges
@Beta(value=V4_37_0, warningText="Preview API - subject to change in non-backwards compatible way") public ChangeFeedProcessorBuilder handleAllVersionsAndDeletesChanges(Consumer<List<ChangeFeedProcessorItem>> consumer) Sets a consumer function which will be called to process changes for AllVersionsAndDeletes change feed mode..handleAllVersionsAndDeletesChanges(docs -> { for (ChangeFeedProcessorItem item : docs) { // Implementation for handling and processing of each ChangeFeedProcessorItem item goes here } })- Parameters:
consumer- theConsumerto call for handling the feeds.- Returns:
- current Builder.
-
options
Sets theChangeFeedProcessorOptionsto be used. Unless specifically set the default values that will be used are:- maximum items per page or FeedResponse: 100
- lease renew interval: 17 seconds
- lease acquire interval: 13 seconds
- lease expiration interval: 60 seconds
- feed poll delay: 5 seconds
- maximum scale count: unlimited
- Parameters:
changeFeedProcessorOptions- the change feed processor options to use.- Returns:
- current Builder.
-
buildChangeFeedProcessor
Builds a new instance of theChangeFeedProcessorwith the specified configuration.- Returns:
- an instance of
ChangeFeedProcessor.
-