Skip to main content

Producer

Trait Producer 

Source
pub trait Producer {
    type Error;

    // Required methods
    fn send(&self, key: &[u8], payload: Vec<u8>) -> Result<(), Self::Error>;
    fn join_blocking(&self, timeout: Duration) -> Result<(), Self::Error>;

    // Provided methods
    fn join(
        &self,
        timeout: Duration,
    ) -> impl Future<Output = Result<(), Self::Error>> + Send + use<Self>
       where Self: Sized + Clone + Send + Sync + 'static,
             Self::Error: Send + 'static { ... }
    fn shared(self) -> SharedProducer
       where Self: Sized + Send + Sync + 'static,
             Self::Error: Error + Send + Sync + 'static { ... }
}
Expand description

Sends serialized inventory records somewhere durable.

Required Associated Types§

Source

type Error

What can go wrong when sending.

Required Methods§

Source

fn send(&self, key: &[u8], payload: Vec<u8>) -> Result<(), Self::Error>

Enqueues one record.

key controls which partition receives the message.

Ok() does not necessarily mean the message will be sent successfully. It just means the message has been enqueued.

Source

fn join_blocking(&self, timeout: Duration) -> Result<(), Self::Error>

Blocks until enqueued records have been delivered, or timeout elapses.

Prefer join from async code.

Provided Methods§

Source

fn join( &self, timeout: Duration, ) -> impl Future<Output = Result<(), Self::Error>> + Send + use<Self>
where Self: Sized + Clone + Send + Sync + 'static, Self::Error: Send + 'static,

Waits for enqueued records to be delivered, or until timeout elapses.

Runs join_blocking on a blocking thread. Returns a future rather than being async fn so it does not borrow self, which a dyn caller’s async_trait boxing requires.

Source

fn shared(self) -> SharedProducer
where Self: Sized + Send + Sync + 'static, Self::Error: Error + Send + Sync + 'static,

Erases this producer’s transport and error type, so one producer can serve several trackers.

use objectstore_inventory_tracker::{InventoryTracker, NoopProducer, Producer};

let producer = NoopProducer.shared();
let tracker = InventoryTracker::new(producer.clone(), "my_gcs_bucket", 1.0);

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<P: Producer + ?Sized> Producer for Arc<P>

Source§

type Error = <P as Producer>::Error

Source§

fn send(&self, key: &[u8], payload: Vec<u8>) -> Result<(), Self::Error>

Source§

fn join_blocking(&self, timeout: Duration) -> Result<(), Self::Error>

Source§

impl<P: Producer + ?Sized> Producer for Box<P>

Source§

type Error = <P as Producer>::Error

Source§

fn send(&self, key: &[u8], payload: Vec<u8>) -> Result<(), Self::Error>

Source§

fn join_blocking(&self, timeout: Duration) -> Result<(), Self::Error>

Implementors§