Interface ICdcRepository
Defines the core contract for retrieving Change Data Capture (CDC) data from SQL Server.
public interface ICdcRepository : IAsyncDisposable, IDisposable
- Inherited Members
Remarks
This interface contains the 5 essential methods for CDC processing: LSN navigation, position retrieval, change detection, and change fetching. For LSN-to-time mapping and advanced navigation, see ICdcRepositoryLsnMapping.
Methods
ChangesExistAsync(byte[], byte[], IEnumerable<string>, CancellationToken)
Checks if changes exist between two LSN positions for the specified capture instances.
Task<bool> ChangesExistAsync(byte[] fromPosition, byte[] toPosition, IEnumerable<string> captureInstances, CancellationToken cancellationToken)
Parameters
fromPositionbyte[]The starting LSN position.
toPositionbyte[]The ending LSN position.
captureInstancesIEnumerable<string>A collection of capture instance names to query for changes.
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.
Returns
- Task<bool>
A task that represents the asynchronous operation, containing a boolean indicating whether changes exist.
FetchChangesAsync(string, int, byte[], byte[], byte[]?, CdcOperationCodes, CancellationToken, string?)
Fetches change rows within an LSN range for the specified capture instance.
Task<IEnumerable<CdcRow>> FetchChangesAsync(string captureInstance, int batchSize, byte[] fromLsn, byte[] toLsn, byte[]? lastSequenceValue, CdcOperationCodes lastOperation, CancellationToken cancellationToken, string? logicalTableName = null)
Parameters
captureInstancestringA capture instance table name to query for changes.
batchSizeintThe number of records to retrieve in the batch.
fromLsnbyte[]The starting LSN position (inclusive).
toLsnbyte[]The ending LSN position (inclusive).
lastSequenceValuebyte[]The last processed sequence value, if any. This is used for processing changes with finer granularity.
lastOperationCdcOperationCodesThe CDC operation code filter for the types of changes to retrieve.
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.
logicalTableNamestringThe logical table name to use in TableName instead of the capture instance. When null, the capture instance name is used (backward-compatible default). This allows handlers to match on the consumer-configured table name (e.g.,
dbo.Customers) rather than the SQL Server capture instance name (e.g.,dbo_Customers).
Returns
- Task<IEnumerable<CdcRow>>
An asynchronous stream of CdcRow instances representing the captured changes.
GetMaxPositionAsync(CancellationToken)
Retrieves the maximum LSN currently available in the database.
Task<byte[]> GetMaxPositionAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.
Returns
- Task<byte[]>
A task that represents the asynchronous operation, containing the maximum LSN as a byte array.
GetMinPositionAsync(string, CancellationToken)
Retrieves the minimum LSN for a specific capture instance.
Task<byte[]> GetMinPositionAsync(string captureInstance, CancellationToken cancellationToken)
Parameters
captureInstancestringThe capture instance to query.
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.
Returns
- Task<byte[]>
A task that represents the asynchronous operation, containing the minimum LSN as a byte array.
GetNextLsnAsync(byte[], CancellationToken)
Retrieves the next Log Sequence Number (LSN) after the specified last processed LSN.
Task<byte[]> GetNextLsnAsync(byte[] lastProcessedLsn, CancellationToken cancellationToken)
Parameters
lastProcessedLsnbyte[]The LSN from which to find the next LSN.
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.