Table of Contents

Class InMemoryCdcProcessor

Namespace
Excalibur.Cdc.InMemory
Assembly
Excalibur.Cdc.dll

In-memory implementation of the CDC processor for testing scenarios.

public sealed class InMemoryCdcProcessor : IInMemoryCdcProcessor, ICdcProcessor<InMemoryCdcChange>, IAsyncDisposable, IDisposable
Inheritance
InMemoryCdcProcessor
Implements
Inherited Members

Remarks

This processor retrieves changes from an IInMemoryCdcStore and processes them through user-provided handlers.

Failure behavior. Changes are taken from the store one at a time, immediately before each is handed to the handler. When a handler throws, or processing is cancelled, the change being handled is consumed: it is not redelivered, and the failure is reported through the propagating exception. Every change that had not yet been handed to a handler remains in the store and is delivered, in the order it was added, by the next call. No change leaves the store without either being handled successfully or being reported through an exception.

Constructors

InMemoryCdcProcessor(IInMemoryCdcStore, IOptions<InMemoryCdcOptions>, ILogger<InMemoryCdcProcessor>)

Initializes a new instance of the InMemoryCdcProcessor class.

public InMemoryCdcProcessor(IInMemoryCdcStore store, IOptions<InMemoryCdcOptions> options, ILogger<InMemoryCdcProcessor> logger)

Parameters

store IInMemoryCdcStore

The in-memory CDC store.

options IOptions<InMemoryCdcOptions>

The in-memory CDC options.

logger ILogger<InMemoryCdcProcessor>

The logger instance.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

ProcessBatchAsync(Func<InMemoryCdcChange, CancellationToken, Task>, CancellationToken)

Processes a single batch of CDC changes and returns.

public Task<int> ProcessBatchAsync(Func<InMemoryCdcChange, CancellationToken, Task> eventHandler, CancellationToken cancellationToken)

Parameters

eventHandler Func<InMemoryCdcChange, CancellationToken, Task>

A delegate that handles each change event.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<int>

The number of events processed in this batch.

Remarks

Use this method for serverless scenarios or when you need explicit control over batch processing cadence.

Delivery semantics are provider-specific and this contract does not strengthen them. Providers differ in whether a batch that ends abnormally — a handler that throws, a cancelled token, a process that stops — redelivers the changes it had already read, and in whether a durable position is advanced on this path at all. Consult the documentation of the provider you register before relying on redelivery, and prefer ICdcStreamProcessor<TEvent, TPosition> where the provider offers it: its position management is explicit, whereas this method's is not part of the shared contract.

Consumer obligation: handlers MUST be idempotent. A provider that does redeliver does so without coordinating with the handler, so a handler that succeeded before a batch failed can be called again with the same change.

A return of zero does not necessarily mean "no changes were available". A provider that holds per-stream state MAY serve overlapping calls single-flight: while one call is processing, a second returns 0 immediately without touching the stream, and the work is picked up by a later invocation. This is specified behaviour rather than a failure — overlapping invocations are ordinary for the documented timer-trigger usage, and refusing them with an exception would surface as an unobserved task exception in most hosts. A provider that does this MUST log each skip so it is distinguishable from a stalled processor. Treat the return value as "changes processed by THIS call", never as "changes outstanding".