pub trait SinkAdapter: Send {
Show 18 methods
// Required methods
fn send(&mut self, event: &Event) -> impl Future<Output = Result<()>> + Send;
fn flush(&mut self) -> impl Future<Output = Result<()>> + Send;
fn close(&mut self) -> impl Future<Output = Result<()>> + Send;
fn name(&self) -> &str;
// Provided methods
fn delivery_guarantee(&self) -> SinkDeliveryGuarantee { ... }
fn idempotent_delivery_capable(&self) -> bool { ... }
fn transactional_checkpoint_barrier_capable(&self) -> bool { ... }
fn queue_depth(&self) -> Option<usize> { ... }
fn flush_tick_interval(&self) -> Option<Duration> { ... }
fn begin_checkpoint_barrier(
&mut self,
) -> impl Future<Output = Result<()>> + Send { ... }
fn commit_checkpoint_barrier(
&mut self,
) -> impl Future<Output = Result<()>> + Send { ... }
fn abort_checkpoint_barrier(
&mut self,
) -> impl Future<Output = Result<()>> + Send { ... }
fn preflight_check(&mut self) -> impl Future<Output = Result<()>> + Send { ... }
fn close_with_timeout(
&mut self,
timeout_ms: u64,
) -> impl Future<Output = Result<()>> + Send { ... }
fn exported_events(&self) -> Option<&[Event]> { ... }
fn delivery_metrics(&self) -> Option<SinkDeliveryMetrics> { ... }
fn is_closed(&self) -> bool { ... }
fn boxed(self) -> BoxedSink
where Self: Sized + 'static { ... }
}Expand description
Trait for sending CDC events to a downstream system.
Implementations must be Send so they can be used across async task boundaries.
All methods take &mut self so the adapter can maintain internal state (e.g. a
connection handle or an in-flight buffer) without an inner Mutex.
§Required methods
Implement at minimum: send, flush, close, name.
§Optional capability declarations
Override delivery_guarantee, idempotent_delivery_capable,
transactional_checkpoint_barrier_capable, queue_depth,
flush_tick_interval, and preflight_check to advertise capabilities
and hints to the runtime.
§Checkpoint barrier protocol
Adapters that support effectively-once delivery must override
transactional_checkpoint_barrier_capable → true and implement all
three barrier methods. The protocol is:
begin_checkpoint_barrier— prepare for a checkpoint commit.commit_checkpoint_barrier— durable commit.abort_checkpoint_barrier— roll back on failure.
§Object-safe wrapper
This trait is not object-safe (uses RPITIT). Use BoxedSink when you
need Box<dyn …> dispatch.
§Implementing SinkAdapter
use rustcdc::{core::{Event, Result}, sink::SinkAdapter};
struct MyKafkaSink { /* ... */ }
impl SinkAdapter for MyKafkaSink {
async fn send(&mut self, event: &Event) -> Result<()> {
// Deliver event to Kafka
Ok(())
}
async fn flush(&mut self) -> Result<()> { Ok(()) }
async fn close(&mut self) -> Result<()> { Ok(()) }
fn name(&self) -> &str { "kafka" }
}Required Methods§
Sourcefn send(&mut self, event: &Event) -> impl Future<Output = Result<()>> + Send
fn send(&mut self, event: &Event) -> impl Future<Output = Result<()>> + Send
Deliver a single CDC event to the sink.
Sourcefn flush(&mut self) -> impl Future<Output = Result<()>> + Send
fn flush(&mut self) -> impl Future<Output = Result<()>> + Send
Flush any internal write buffer, making all previously send-ed events
durable (or at least submitted to the downstream system).
Provided Methods§
Sourcefn delivery_guarantee(&self) -> SinkDeliveryGuarantee
fn delivery_guarantee(&self) -> SinkDeliveryGuarantee
The delivery guarantee this adapter offers.
Default: SinkDeliveryGuarantee::AtLeastOnce.
Sourcefn idempotent_delivery_capable(&self) -> bool
fn idempotent_delivery_capable(&self) -> bool
Whether the adapter can deliver an event idempotently (e.g. upsert by key).
Default: false.
Sourcefn transactional_checkpoint_barrier_capable(&self) -> bool
fn transactional_checkpoint_barrier_capable(&self) -> bool
Whether the adapter supports the transactional checkpoint barrier protocol.
Adapters that return true here must implement
begin_checkpoint_barrier,
commit_checkpoint_barrier, and
abort_checkpoint_barrier.
Default: false.
Sourcefn queue_depth(&self) -> Option<usize>
fn queue_depth(&self) -> Option<usize>
Current number of events buffered in-memory and not yet flushed.
Used by the runtime to observe back-pressure. Return None when the
adapter does not maintain an internal buffer.
Default: None.
Sourcefn flush_tick_interval(&self) -> Option<Duration>
fn flush_tick_interval(&self) -> Option<Duration>
Suggest how often the runtime should call flush
on a time basis (e.g. when the sink batches events by time window).
The runtime will arrange for periodic flushing no less often than this
interval. Return None to leave flushing entirely to the runtime’s
checkpoint / batch schedule.
Default: None.
Sourcefn begin_checkpoint_barrier(
&mut self,
) -> impl Future<Output = Result<()>> + Send
fn begin_checkpoint_barrier( &mut self, ) -> impl Future<Output = Result<()>> + Send
Begin a transactional checkpoint barrier.
Called before the pipeline commits a checkpoint offset to durable
storage. The adapter should hold new sends buffered until
commit_checkpoint_barrier or
abort_checkpoint_barrier is called.
Default: no-op Ok(()).
Sourcefn commit_checkpoint_barrier(
&mut self,
) -> impl Future<Output = Result<()>> + Send
fn commit_checkpoint_barrier( &mut self, ) -> impl Future<Output = Result<()>> + Send
Commit the in-flight checkpoint barrier.
The adapter should atomically make buffered events durable and release the barrier.
Default: no-op Ok(()).
Sourcefn abort_checkpoint_barrier(
&mut self,
) -> impl Future<Output = Result<()>> + Send
fn abort_checkpoint_barrier( &mut self, ) -> impl Future<Output = Result<()>> + Send
Abort the in-flight checkpoint barrier and discard buffered events.
Called when a downstream failure makes the current checkpoint uncompletable.
Default: no-op Ok(()).
Sourcefn preflight_check(&mut self) -> impl Future<Output = Result<()>> + Send
fn preflight_check(&mut self) -> impl Future<Output = Result<()>> + Send
Validate that the sink can accept events before the pipeline starts.
The runtime calls this once during startup. Use it to fail-fast on misconfigured endpoints, missing credentials, or unreachable services.
Default: no-op Ok(()).
Sourcefn close_with_timeout(
&mut self,
timeout_ms: u64,
) -> impl Future<Output = Result<()>> + Send
fn close_with_timeout( &mut self, timeout_ms: u64, ) -> impl Future<Output = Result<()>> + Send
Close the adapter, returning Error::TimeoutError if the close takes
longer than timeout_ms milliseconds.
Use this in shutdown paths where a hung sink must not prevent the process from exiting. The adapter state is indeterminate after a timeout.
Sourcefn exported_events(&self) -> Option<&[Event]>
fn exported_events(&self) -> Option<&[Event]>
Optional inspection hook for deterministic conformance assertions.
Adapters that can safely expose a read-only in-memory view of all received
events should return Some. Opaque adapters (writing to an external system)
may return None.
Sourcefn delivery_metrics(&self) -> Option<SinkDeliveryMetrics>
fn delivery_metrics(&self) -> Option<SinkDeliveryMetrics>
Snapshot of delivery counters for observability.
Override to expose per-sink metrics to admin endpoints or Prometheus scrapers.
Returns None when the adapter does not track delivery counters.
Default: None.
Sourcefn is_closed(&self) -> bool
fn is_closed(&self) -> bool
Whether the adapter has been closed.
Returns true after close has been called. The default implementation
always returns false.
Adapters that need to pass BasicAdapterConformance checks must override
this method — the crash_recovery conformance test asserts that is_closed()
returns true after close() is called. Relying on the default will cause
conformance failures.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".