pub trait Sink: Send + Sync {
// Required method
fn write(
&self,
batch: WriteBatch,
) -> impl Future<Output = Result<WriteAck, SinkError>> + Send;
}Expand description
Where writes go.
Isolating the destination behind a trait keeps routing decisions independent
of delivery (docs/decisions/008): OpenSearchSink writes directly to a
cluster today, and a future QueueSink (Kafka) can take the same
WriteBatch for the redundancy mode with no change to the engine.
§Invariants
- MUST NOT panic; return
SinkErrorfor every failure (NFR-R1). - The returned
WriteAckMUST carry one result per batch operation, in the batch’s original order, so a bulk response can be re-interleaved (M3).
§Examples
use osproxy_core::{ClusterId, Epoch, IndexName, Target};
use osproxy_sink::{DocOp, MemorySink, Sink, WriteBatch, WriteOp};
let sink = MemorySink::new();
let op = WriteOp::new(
Target::new(ClusterId::from("c"), IndexName::from("i")),
DocOp::Index { id: Some("p:1".into()), routing: Some("p".into()), body: bytes::Bytes::from_static(b"{}") },
Epoch::new(1),
);
let ack = sink.write(WriteBatch::single(op)).await.unwrap();
assert!(ack.all_succeeded());
assert_eq!(sink.recorded().len(), 1);Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".