Struct rdkafka::consumer::BaseConsumer[][src]

pub struct BaseConsumer<C = DefaultConsumerContext> where
    C: ConsumerContext
{ /* fields omitted */ }

A low-level consumer that requires manual polling.

This consumer must be periodically polled to make progress on rebalancing, callbacks and to receive messages.

Implementations

impl<C> BaseConsumer<C> where
    C: ConsumerContext
[src]

pub fn poll<T: Into<Timeout>>(
    &self,
    timeout: T
) -> Option<KafkaResult<BorrowedMessage<'_>>>
[src]

Polls the consumer for new messages.

It won’t block for more than the specified timeout. Use zero Duration for non-blocking call. With no timeout it blocks until an event is received.

This method should be called at regular intervals, even if no message is expected, to serve any queued callbacks waiting to be called. This is especially important for automatic consumer rebalance, as the rebalance function will be executed by the thread calling the poll() function.

Lifetime

The returned message lives in the memory of the consumer and cannot outlive it.

pub fn iter(&self) -> Iter<'_, C>

Notable traits for Iter<'a, C>

impl<'a, C> Iterator for Iter<'a, C> where
    C: ConsumerContext
type Item = KafkaResult<BorrowedMessage<'a>>;
[src]

Returns an iterator over the available messages.

It repeatedly calls poll with no timeout.

Note that it’s also possible to iterate over the consumer directly.

Examples

All these are equivalent and will receive messages without timing out.

loop {
  let message = consumer.poll(None);
  // Handle the message
}
for message in consumer.iter() {
  // Handle the message
}
for message in &consumer {
  // Handle the message
}

pub fn split_partition_queue(
    self: &Arc<Self>,
    topic: &str,
    partition: i32
) -> Option<PartitionQueue<C>>
[src]

Splits messages for the specified partition into their own queue.

If the topic or partition is invalid, returns None.

After calling this method, newly-fetched messages for the specified partition will be returned via PartitionQueue::poll rather than BaseConsumer::poll. Note that there may be buffered messages for the specified partition that will continue to be returned by BaseConsumer::poll. For best results, call split_partition_queue before the first call to BaseConsumer::poll.

You must continue to call BaseConsumer::poll, even if no messages are expected, to serve callbacks.

Note that calling Consumer::assign will deactivate any existing partition queues. You will need to call this method for every partition that should be split after every call to assign.

Beware that this method is implemented for &Arc<Self>, not &self. You will need to wrap your consumer in an Arc in order to call this method. This design permits moving the partition queue to another thread while ensuring the partition queue does not outlive the consumer.

Trait Implementations

impl<C> Consumer<C> for BaseConsumer<C> where
    C: ConsumerContext
[src]

impl<C> Drop for BaseConsumer<C> where
    C: ConsumerContext
[src]

impl FromClientConfig for BaseConsumer[src]

impl<C: ConsumerContext> FromClientConfigAndContext<C> for BaseConsumer<C>[src]

Creates a new BaseConsumer starting from a ClientConfig.

impl<'a, C> IntoIterator for &'a BaseConsumer<C> where
    C: ConsumerContext
[src]

type Item = KafkaResult<BorrowedMessage<'a>>

The type of the elements being iterated over.

type IntoIter = Iter<'a, C>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<C> RefUnwindSafe for BaseConsumer<C> where
    C: RefUnwindSafe

impl<C> Send for BaseConsumer<C>

impl<C> Sync for BaseConsumer<C>

impl<C> Unpin for BaseConsumer<C>

impl<C> UnwindSafe for BaseConsumer<C> where
    C: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.