Partilhar via


ChangeFeedProcessor Interface

public interface ChangeFeedProcessor

Simple host for distributing change feed events across observers, simplifying the process of reading the change feeds and distributing the processing events across multiple consumers effectively.

There are four main components of implementing the change feed processor:

  • The monitored container: the monitored container has the data from which the change feed is generated. Any inserts and updates to the monitored container are reflected in the change feed of the container.
  • The lease container: the lease container acts as a state storage and coordinates processing the change feed across multiple workers. The lease container can be stored in the same account as the monitored container or in a separate account.
  • The host: a host is an application instance that uses the change feed processor to listen for changes. Multiple instances with the same lease configuration can run in parallel, but each instance should have a different instance name.
  • The delegate: the delegate is the code that defines what you, the developer, want to do with each batch of changes that the change feed processor reads.

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();

Method Summary

Modifier and Type Method and Description
abstract Mono<List<ChangeFeedProcessorState>> getCurrentState()

Returns a read only list of list of objects, each one represents one scoped worker item.

abstract Mono<Map<String,Integer>> getEstimatedLag()

Returns the current owner (host) and an approximation of the difference between the last processed item (defined by the state of the feed container) and the latest change in the container for each partition (lease item).

abstract boolean isStarted()

Returns the state of the change feed processor.

abstract Mono<Void> start()

Start listening for changes asynchronously.

abstract Mono<Void> stop()

Stops listening for changes asynchronously.

Method Details

getCurrentState

public abstract Mono> getCurrentState()

Returns a read only list of list of objects, each one represents one scoped worker item.

An empty list will be returned if the processor was not started or no lease items matching the current ChangeFeedProcessor instance's lease prefix could be found.

Returns:

a Mono containing a read only list of objects, each one representing one scoped worker item.

getEstimatedLag

public abstract Mono> getEstimatedLag()

Returns the current owner (host) and an approximation of the difference between the last processed item (defined by the state of the feed container) and the latest change in the container for each partition (lease item).

An empty map will be returned if the processor was not started or no lease items matching the current ChangeFeedProcessor instance's lease prefix could be found.

Returns:

a map representing the current owner and lease token, the current LSN and latest LSN, and the estimated lag, asynchronously.

isStarted

public abstract boolean isStarted()

Returns the state of the change feed processor.

Returns:

true if the change feed processor is currently active and running.

start

public abstract Mono start()

Start listening for changes asynchronously.

Returns:

a representation of the deferred computation of this call.

stop

public abstract Mono stop()

Stops listening for changes asynchronously.

Returns:

a representation of the deferred computation of this call.

Applies to