pub trait Sink:
Send
+ Sync
+ 'static {
type Error: StdError + Send + Sync + 'static;
// Required method
fn try_send(
&self,
data: &[u8],
) -> impl Future<Output = Result<(), SinkError<Self::Error>>> + Send;
// Provided method
fn health_check(
&self,
) -> impl Future<Output = Result<(), Self::Error>> + Send { ... }
}Available on crate feature
tiered-sink only.Expand description
A sink that can receive messages asynchronously.
Implement this trait for your message backend (Kafka, S3, HTTP, etc.)
to use with TieredSink.
Async methods return impl Future + Send to ensure compatibility with
tokio::spawn.
§Example
ⓘ
use hyperi_rustlib::tiered_sink::{Sink, SinkError};
struct MyKafkaSink {
producer: KafkaProducer,
}
impl Sink for MyKafkaSink {
type Error = KafkaError;
async fn try_send(&self, data: &[u8]) -> Result<(), SinkError<Self::Error>> {
match self.producer.send(data).await {
Ok(()) => Ok(()),
Err(e) if e.is_queue_full() => Err(SinkError::Full),
Err(e) if e.is_broker_unavailable() => Err(SinkError::Unavailable),
Err(e) => Err(SinkError::Fatal(e)),
}
}
}Required Associated Types§
Required Methods§
Sourcefn try_send(
&self,
data: &[u8],
) -> impl Future<Output = Result<(), SinkError<Self::Error>>> + Send
fn try_send( &self, data: &[u8], ) -> impl Future<Output = Result<(), SinkError<Self::Error>>> + Send
Try to send data to the sink.
This should be non-blocking or have a short timeout.
Return appropriate SinkError variant based on the failure mode:
SinkError::Full- Sink is backpressuring, try again laterSinkError::Unavailable- Sink is down, circuit breakSinkError::Fatal(e)- Unrecoverable error, don’t spool
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".