Skip to main content

new

pub fn new<F>(function: F) -> impl OffsetCommitCallback
Expand description

Returns an OffsetCommitCallback that calls function, standing in for a Java lambda implementing OffsetCommitCallback: function is on_complete, run synchronously as Java’s onComplete is. A method Java adds later as an overload of onComplete gets its own factory, with_<parameter>.

use std::sync::Arc;

use confluent_kafka::consumer::{offset_commit_callback, OffsetCommitCallback};

let callback: Arc<dyn OffsetCommitCallback> = Arc::new(offset_commit_callback::new(|offsets, error| {
    match error {
        Some(error) => eprintln!("commit of {} partitions failed: {error}", offsets.len()),
        None => println!("committed {} partitions", offsets.len()),
    }
    Ok(())
}));

§Arguments

  • function - the body of on_complete, called with the committed offsets and the commit’s error.