pub struct Consumer<T, F>{ /* private fields */ }Expand description
A Consumer that can be used to consume messages from kafka
Implementations§
Source§impl<T, F> Consumer<T, F>
impl<T, F> Consumer<T, F>
Sourcepub fn with_options(options: ConsumerOptiopns<'_>) -> Result<Self, Error>
pub fn with_options(options: ConsumerOptiopns<'_>) -> Result<Self, Error>
Creates a new Consumer from consumer options
§Arguments
options- A ConsumerOptions struct that holds the consumer options
§Example
use simple_kafka::{Consumer, ConsumerOptiopns};
let options = ConsumerOptiopns {
bootstrap_servers: "localhost:9092".to_string(),
group_id: "group_id".to_string(),
session_timeout_ms: "6000".to_string(),
enable_auto_commit: true,
enable_partition_eof: false,
};
let consumer = Consumer::with_options(options).unwrap();Sourcepub async fn subscribe_to_topic<H>(&mut self, topic: &str, handler: H)where
H: Fn(KafkaResult<T>) -> F,
pub async fn subscribe_to_topic<H>(&mut self, topic: &str, handler: H)where
H: Fn(KafkaResult<T>) -> F,
Subscribe to a given topic and calls the given function for each message
§Arguments
topic- The topic to subscribe tohandler- The handler function that will be called for each message for the givetopic
§Example
use simple_kafka::{Consumer};
#[derive(Serialize, Deserialize, Debug)]
struct Data {
attra_one: String,
attra_two: i8,
}
let mut consumer = Consumer::from("group_id", "localhost:9092");
let handler = consumer.subscribe_to_topic("topic".to_string(), |data: Data, medatad: Metadata| async move {
info!("data: {:?}, metadata: {:?}", data, medatad);
});
handler.await;Auto Trait Implementations§
impl<T, F> Freeze for Consumer<T, F>
impl<T, F> !RefUnwindSafe for Consumer<T, F>
impl<T, F> !Send for Consumer<T, F>
impl<T, F> !Sync for Consumer<T, F>
impl<T, F> Unpin for Consumer<T, F>
impl<T, F> !UnwindSafe for Consumer<T, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more